samedi 17 octobre 2015

Pseudo random numbers generation in a given interval of values in c++

I'm looking for a couple of function that works in a similar fashion of srand(unsigned int) and rand(void) but, with a variable range instead of a fixed one.

I don't like the script

srand(time(NULL));
random_number = rand() % (h_limit - l_limit) + l_limit;

for two reasons. The first one is that a number can be repeated. The second one is that, for large limits, the probability density function is not a costant.

I think that a good solution could be redefine RAND_MAX that is the upper limit of classical functions. Is this a good way to solve my problem or there might be problems? Have you a better way to proceed?




Aucun commentaire:

Enregistrer un commentaire