How to generate a random number in C

To generate a random number in C you can use the following snippet.

Sample C

srand(time(NULL));
int r = rand() % 10; //generates a random number between 0 and 9
printf("%d",r);

Please Share us:
Please rate this snippet

One thought on “How to generate a random number in C

Leave a Reply