modulo? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

modulo?

hey there. i just learnt that with rand i am able to define a range of number (eg.1 to 20), my question is as i haven't seen any example in the lessons, how can i define a minimum value (eg.5 to 15)???

22nd Jun 2017, 9:49 AM
kelo
2 Answers
+ 8
You need to figure out the math. There is no one single way to deal with range for RNG. E.g. 5 to 15 std::cout << (5 + rand() % 11); Now, if I want to generate random even numbers between 10 to 50? Random numbers which are multiples of 10 between 100 to 200?
22nd Jun 2017, 11:00 AM
Hatsy Rei
Hatsy Rei - avatar
0
thanks for the answer :).
23rd Jun 2017, 1:03 PM
kelo