At the following: http://www.fredosaurus.com/notes-cpp/misc/random.html
It mentions that if we want to generate a random number in the range 1-10
, we ca
The modulo part is answered by others. You must initialize with srand(time(0)) because otherwise you will get the same series of random numbers each time your program runs.
As far as I understand it, this is because the generator starts with a certain number and following numbers are calculated based on this starting number.
You can initialise with any number you like, for example for testing you could use srand(0) and get the same numbers as in the last run. To get a fully random series you use time(0) because that initialises with the actual time in seconds Which is random enough for most purposes.