srand() and If-statements | Sololearn: Learn to code for FREE!


srand() and If-statements

How do I generate a number when I have multiple If-statements? Where should I place the srand() function, before or after conditions? And what else do I need to add to the code

11/27/2016 12:21:35 PM

Julia Melnik

3 Answers

New Answer


To generated random number you need to use rand() function and srand() function use to initialization of rand. Put your srand above if statement. And initialize rand by srand(time(NULL)). You have to use ctime header file for time function. it would work perfect. if you want it within a range use rand()%(max-min+1)+min