samedi 30 décembre 2017

More about Random in Java: get almost real randomization [duplicate]

This question already has an answer here:

I was experimenting with Random class in Java and, as many others here on Stack Overflow, I noticed that using a seed will always give the same result (and it's okay, seems logic), but I still have a (theoretical) question: what's the real difference between giving a chosen seed and System.currentTimeMillis as seed? Testing the same program, the same time of the day, won't give me the same results after multiple tries?

I know it's really hard for me to obtain the same exact result, but if my program were to be used by millions, or billions of people, few could get the same results in terms of randomization, for example: Imagine a getpoints.exe where you have to click a bottom and get a random amount of points depending on the time of the day. Using Random(System.currentTimeMillis) won't be random over all because two people clicking at the same exact time will get the same amount, so the result won't be really random. The same applies if 1mln people press it simultaneously.

So the original question: are there pseudo-real but more accurate ways to get random numbers?




Aucun commentaire:

Enregistrer un commentaire