How to use the clock as a random generator seed in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    // Seed the random number generator with the current time
    srand(time(NULL));

    // Generate and print a random number
    int random_number = rand();
    printf("Random number: %d\n", random_number);

    return 0;
}


/*
run:

Random number: 1496947276

*/

 



answered May 7 by avibootz
...