Hello every1 this is my first post in these forums, and i would like to say hello to the c++ community. Now in order to cut to the chase, i would like to ask specifically how the rand() function works. It is obvious to me, that it is a random number generator essentially, but does it have any "caps" to the numbers it generates? In addition is it possible that i may apply hard caps to it, like saying i want it to generate numbers between 10 and 100 or something like that?
rand() generates pseudo random numbers in the range [0,RAND_MAX]
To get numbers in the range [0,n-1] ( with n < RAND_MAX ) you can call the modulo operator: rand() % n
To get them in the range [m,n-1] ( with 0 < m < n < RAND_MAX )
simply use modulo combined with addition and subtraction: rand() % ( n-m ) + m http://www.cplusplus.com/reference/clibrary/cstdlib/rand/