| Author |
random number output
|
|
| patrick_woflian 2005-11-24, 9:56 pm |
| hello, i just wondering how you write out the code in java to acheive
an output of a random number between one and twelve.. any takers?
thanks very much
| |
| Oliver Wong 2005-11-24, 9:56 pm |
| "patrick_woflian" <gingercrock@hotmail.com> wrote in message
news:1132850424.939534.192340@o13g2000cwo.googlegroups.com...
> hello, i just wondering how you write out the code in java to acheive
> an output of a random number between one and twelve.. any takers?
> thanks very much
>
see java.util.Random
http://java.sun.com/j2se/1.5.0/docs...til/Random.html
- Oliver
| |
| Allan Bruce 2005-11-24, 9:56 pm |
|
"patrick_woflian" <gingercrock@hotmail.com> wrote in message
news:1132850424.939534.192340@o13g2000cwo.googlegroups.com...
> hello, i just wondering how you write out the code in java to acheive
> an output of a random number between one and twelve.. any takers?
> thanks very much
>
Random r = new Random(); // in java.util.Random
int randomNumber = r.nextInt(12)+1;
Allan
| |
| Thomas Fritsch 2005-11-24, 9:56 pm |
| patrick_woflian wrote:
> hello, i just wondering how you write out the code in java to acheive
> an output of a random number between one and twelve.. any takers?
> thanks very much
>
Reading the JavaDocs of java.util.Random will help.
--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
| |
|
| Hi ,
U can also genarate random numbers in this way
int x=(int)Math.random()%12+1
Bye,
Ravi.
| |
| Roedy Green 2005-11-26, 9:57 pm |
| On 25 Nov 2005 22:18:34 -0800, "Ravi" <ravindra4me@gmail.com> wrote,
quoted or indirectly quoted someone who said :
>int x=(int)Math.random()%12+1
that won't work. For why see
http://mindprod.com/jgloss/pseudorandom.html#BADCODE
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
|
|