0
How to make an random int greater than a number and less than another number?
I want to make an random number to be in an area of int. How can I do this with a mathematical solve?
2 Réponses
+ 3
In C++:
rand() % (max - min + 1) + min;
where max is the upper limit and min the lower limit. Note that +1 is there to include max into the range of numbers you can get.
This works only for positive integers though.
Another approach would be to use objects from the random library (distributions), because here you can specify the range when constructing the object:
http://www.cplusplus.com/reference/random/
0
thx