+ 1
How to set the range for generating random numbers in C using rand() function?
4 odpowiedzi
+ 4
Oh ok Kishalaya Saha, Thanks for answering / explaining, much appreciated : )
+ 1
Hi 「HAPPY TO HELP」 the second ex shows 'rand() % 50 + 1' and the third is 'rand() % 51' these looks the same to me, can you help me understand how they yield different output?
Thanks : )
+ 1
Ipang, it's the lower limit of the number that is different, which 「HAPPY TO HELP」 called the MINIMUM. The third one starts from 0, while the second one starts from 1.
The remainder modulo 50 is a number between 0 and 49 (both inclusive). Add 1 to that, and you get numbers between 1 (=0+1) and 50(=49+1).
0
Happy to help 😉