DEV Community

Discussion on: Rock Paper Scissor in C

Collapse
 
pentacular profile image
pentacular
int generateRandomNumber(int n)
{
    srand(time(NULL));
    return rand() % n;
}

This is equivalent to applying a hash function to the clock with a resolution of one second.

It means that rand() isn't following a pseudo-random number sequence, and that if you call it N times within the same second you'll get the same answer N times.

Use srand() once, initially in main, to select a pseudo-random number sequence to iterate using rand.