Friday, 13 September 2013

random() not working in C

random() not working in C

I am currently learning C though "C all-in-one Desk Reference for Dummies"
and came to the point where it starts teaching how to get random numbers.
However, the sample code it gives doesn't work (the compiler comes up with
an error "undefined reference to 'random'"). My code is below, copied from
the book.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int hat;
hat = random();
printf("%d is a random number.\n",hat);
return(0);
}

No comments:

Post a Comment