Mr Plow
Posts: 18
Nickname: mrplow
Registered: Jun, 2003
|
|
Re: Random pages in Java
|
Posted: Aug 15, 2003 12:07 AM
|
|
Jeff -
java.lang.Math.random() "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0" (From the Java 1.4.1 API)
Therefore by using a statement like: int randInt = (int)(Math.random() * 100) + 1; you can get a random integer value between 1 and 100.
Alternatively, you could create an instance of java.util.Random, and then use the methods nextInt(), nextLong(), nextFloat(), nextDouble() to get a random number of the appropriate type.
|
|