I\'m trying to generate random number between 0 and 40(inclusive). So the code I Implemented is this-
y=rand()%41;
However everytime I click c
rand()
generates only pseudorandom numbers. This means that every time you run your code you will get exactly the same sequence of numbers.
Consider using
srand(time(NULL))
to get every time different numbers. In fact a possible implementation for rand
is
next = next * 1103515245 + 12345;
return (UINT32)(next>>16) & RAND_MAX;
where next
is defined as
static UINT32 next = 1;
Calling srand()
has the effect of changing the initial value of next
, thus changing the "next" value you get as result.