vendredi 27 février 2015

Algorithm to generate positive random integers smaller than given integer n

There are algorithms to generate random numbers like:



number = (previous_number * constant + other_constant) mod third_constant


for carefully selected constants. But I need algorithm to generate random integers that are in range of 0 to n-1. (Obviously not running loop and getting the counter, I need randomness). How is this possible? Thank you.





Aucun commentaire:

Enregistrer un commentaire