Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Array List
|
Posted: May 2, 2002 12:24 PM
|
|
Bon Jour Thomas,
If you use the default constructor of Random, you don't need to specify a seed and it will use the current time automatically.
Also, in this case, it might be easier to use Math.random(), which returns a double. However, she was also asking for an unbounded value, while this method as well as the nextFloat() and nextDouble() methods of Random return a value between 0.0 and 1.0. I guess if you want a random number in the range of all doubles (or floats) then you could multiply the result of this random value by Double.MAX_VALUE (or Float.MAX_VALUE, as it were). This approach is probably statistically flawed, but it is probably close enough for homework. Also, if you want both positive and negative values, you could first subtract 0.5 from the random result, or you could do another call to the random number generator to decide positive/negative.
|
|