+ 1
Srand
is it possible to get random numbers of certain intervals. say I want a random number between 0-100 of 10s?
7 odpowiedzi
+ 10
Number greater than 25, less than (or equals to?) 100 and multiple of 10.
int rand_num = 30 + ((rand() % 8) * 10);
+ 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.
+ 1
yep that makes sense. thanks
+ 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.
0
what about this. what if I want a random number between 0 and 50 in multiples of 10
0
nvmd I see it now
0
your so smart