Java: Random with a random seed
new Random()
initializes with a random seed.
new Random(long seed)
initializes using the given seed.
Example:
// Different each time
new Random().nextInt() // == 1224474278
new Random().nextInt() // == 518936335
new Random().nextInt() // == -1613359952
// Same each time
new Random(5555).nextInt() // == 168436389
new Random(5555).nextInt() // == 168436389
new Random(5555).nextInt() // == 168436389
See also
Comments
Be the first to comment!