using rand to generate a random numbers

You’re seeding inside the loop (with the same value because of how quickly the loop will be executed), which causes the random number generated to be the same each time.

You need to move your seed function outside the loop:

/* Initialize random number */
srand((unsigned int)time(NULL));

for(i = 0; i < 3; i++) {
    /* Added random number (simulate seconds) */
    add((rand() % 30) + 1);
}

Leave a Comment