![]() With the nextInt() method, you can obtain random integers: int randomInt = rand.nextInt() // produces a random integerįor a range, say between 0 (inclusive) and a given bound (exclusive): int boundedRandomInt = rand.nextInt(10) // produces a random integer between 0 and 9 This will use the current time in milliseconds as a seed: Random rand = new Random() // creates a new random number generator To create an instance of the Random class, you can use the default constructor. It internally uses a linear congruential generator to produce these values. The Java Random class, available in the java.util package, provides an easy and flexible way to produce random values of different types.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |