how to generate random number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to generate random number?

for example from 1 to 10

18th Oct 2017, 1:25 PM
boyd
boyd - avatar
1 Answer
+ 1
Use the rand() function. It's mentioned in the tutorial, if you haven't gotten there yet. srand(time(0)); // makes rand() actually random cout << rand() % 10 + 1; // generates random # from 1 to 10
18th Oct 2017, 2:21 PM
LunarCoffee
LunarCoffee - avatar