I'm looking at the documentation for random():
It returns successive pseudo-random numbers in the range from 0 to (2**31)-1.
I don't want it to return 0 ever.
I'm thinking about writing:
long rand = random() + 1;
But if I'm not mistaken, long can be 32-bits on a 32-bit processor. I guess I would risk stack overflow then.
What is the best approach to getting a random number between 1 and (2**31)-1?
Aucun commentaire:
Enregistrer un commentaire