jeudi 10 novembre 2016

How do I generate a (pseudo) random float between 0 and a small floating point number in C++?

So I need to generate a very small random number within a range. I've got how to generate a random number between 0 and 1, that would be:

srand(time(NULL));

followed by:

float posx = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);

My question is: How can I get the random number to be between, say, 0 and 0.1 or maybe even smaller than that?

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire