vendredi 6 mai 2016

Generate a random number less than 4 digits but the probability of it having 1, 2, or 3 digits is equal

I'm currently using (int)(rand() * 1000.0 / RAND_MAX) to generate a random number between 0 and 999 but the two and one digit numbers don't occur as often as the three digit numbers.

How can I fix this?




Aucun commentaire:

Enregistrer un commentaire