+ 1

Srand

is it possible to get random numbers of certain intervals. say I want a random number between 0-100 of 10s?

5th Jun 2017, 3:01 PM
Bryan
7 Réponses
+ 10
Number greater than 25, less than (or equals to?) 100 and multiple of 10. int rand_num = 30 + ((rand() % 8) * 10);
5th Jun 2017, 3:48 PM
Hatsy Rei
Hatsy Rei - avatar
+ 9
srand(time(0)); int rand_num = (rand() % 11) * 10; // This would give you 0 to 100 with intervals of 10. It is easy if you understand the math behind it.
5th Jun 2017, 3:28 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
yep that makes sense. thanks
5th Jun 2017, 3:30 PM
Bryan
+ 1
actually yeah. so that works for multiples of 10 such as 100 or 50 but what if I actually want a number greater than 25 less than 100 and multiple of 10. I thought 100-((rand()%2.5)*10) but that could only give you 90 or 80.
5th Jun 2017, 3:37 PM
Bryan
0
what about this. what if I want a random number between 0 and 50 in multiples of 10
5th Jun 2017, 3:33 PM
Bryan
0
nvmd I see it now
5th Jun 2017, 3:34 PM
Bryan
0
your so smart
5th Jun 2017, 4:20 PM
Bryan