mardi 22 septembre 2015

Java - Efficient way to generate lots of random numbers

I have a java method that has to generate lots of random numbers in a very short period of time. My first approach was to use Math.random (which works really fast), but I have the presumption that because I call the Math.random so quick on behind the other, the "random" isn't really random (or less random) because of that (but I need it to be as random as possible).

I now have two questions:

  1. Is my presumption right, that because of the number of calls in a very short period of time the random output gets less random? And if the answer for 1. is Yes:
  2. What would be the fastest way (per call) to remove the problem with the less randomness?

I have already played around with the SecureRandom, but it is minimum 15 times slower than the normal Math.random, which is too slow for my requirements.

Thank you for your support :)




Aucun commentaire:

Enregistrer un commentaire