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