Board index » jbuilder » method to generate random number

method to generate random number


2003-07-02 04:42:14 AM
jbuilder18
Hi,
I need a method to generate a random number between zero and X, X being a
variable set by my program. The only method I can find is Math.random(),
which generates a number between 0.0 and 1.0. (Of course, I can multiply to
make it an int). Can you help me out?
Thanks!
 
 

Re:method to generate random number

Nechama Shuchatowitz wrote:
Quote
Hi,

I need a method to generate a random number between zero and X, X
being a variable set by my program. The only method I can find is
Math.random(), which generates a number between 0.0 and 1.0. (Of
course, I can multiply to make it an int). Can you help me out?

Thanks!
Try java.util.Random and it's nextInt() method.
hth
 

Re:method to generate random number

Why don't you want to multiply it (as you suggested)? This is the way it is
intended to be used.
"Nechama Shuchatowitz" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I need a method to generate a random number between zero and X, X being a
variable set by my program. The only method I can find is Math.random(),
which generates a number between 0.0 and 1.0. (Of course, I can multiply
to
make it an int). Can you help me out?

Thanks!


 

{smallsort}