i want to generate a random number by using the system time. i dont know how to do it. And another thing is, how to find the millisecond? please help me
help me to generate a random number on the basis of system time
Collapse
X
-
Tags: None
-
-
-
Use this statement at the very beginning of your main() function:
In order to limit your values, use the modulus operator (%) with the range of values you wanted. Suppose you wanted a value between 0 and 50 (including 0, but not 50). Use the statement:Code:srand((unsigned)time(0));
If you want to have a higher minimum value (such as 50 to 100 including 50 but not 100), useCode:int x = rand() % 50;
Code:int x = rand() % 50 + 50; // Generates random number between 0 and 50, then adds 50 to it
Comment
Comment