mercredi 26 février 2020

How is Java's Random seeded by default? [duplicate]

See title. I noticed that I don't have to set a seed for Java's Random object to generate random numbers. What is the default seed? I ask because I just ran a method that utilized Random generator = new Random() in multiple trials and got similar output, but then I used Random generator = new Random(System.currentTimeMillis()) and got very different output. This lead me to believe that I'm creating random numbers incorrectly.

My suspicion was that the default seed is the same between generation, but then I tried making new objects without a seed argument and they are indeed different.

Does anyone know why this would be the case?




Aucun commentaire:

Enregistrer un commentaire