Generating Random Numbers with a Specified Seed

suggest change
//Creates a Random instance with a seed of 12345.
Random random = new Random(12345L);

//Gets a ThreadLocalRandom instance
ThreadLocalRandom tlr = ThreadLocalRandom.current();

//Set the instance's seed.

Using the same seed to generate random numbers will return the same numbers every time, so setting a different seed for every Random instance is a good idea if you don’t want to end up with duplicate numbers.

A good method to get a Long that is different for every call is System.currentTimeMillis():

Random random = new Random(System.currentTimeMillis());

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents