jeudi 25 juin 2015

Random number generation algorithm

I encountered a naive algorithm for random number generation that produce a series of numbers as follows:

for (int i = 0; i < MAX; i++)
   if (rand.nextInt(100) >= 100 - probability) // probability is between 0 and 100
       randomNumbersList.add(i);

I was wondering if there's a way to achieve statistically equivalent results without iterating through each number between 0 and MAX.




Aucun commentaire:

Enregistrer un commentaire