Lucas Lucas - 3 months ago 12
C Question

How to generate a random number in C?

Is there a function to generate a random number in C? Or will I have to use a third party library?

Answer
#include <time.h>
#include <stdlib.h>

srand(time(NULL));
int r = rand();    //returns a pseudo-random integer between 0 and RAND_MAX
Comments