mercredi 15 juillet 2020

How does java Random() find a seed?

from my research everyone seems to say that java random uses the system time in milliseconds as its default seed when one is not specified. So, following this if we have the system time at the moment a random number is generated we should be able to know what seed generates that number. So,

(new Random()).nextLong;
long time = System.currentTimeMillis();
(new Random(time)).nextLong

should produce two identical numbers as the seed is the same, right? It doesn't so either it doesn't use TimeMillis as the seed or I'm doing something else wrong.

Thanks so much for any help, I've searched for hours but can't seem to find a consistent answer. I just want to know exactly how it finds a seed when one is not specified. My thinking is maybe it does use the system time but it multiplies it etc before coming to a final seed.

Thanks again :)




Aucun commentaire:

Enregistrer un commentaire