Seed the generator once at the start of your program. Although even then it will only be pseudo-random. You'd have to go to something like radiation if you want "truly random" numbers.
/* srand example */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
printf ("First number: %d\n", rand() % 100);
srand ( time(NULL) );
printf ("Random number: %d\n", rand() % 100);
srand ( 1 );
printf ("Again the first number: %d\n", rand() %100);
return 0;
}
If you have an application that needs a random number once during its life time then you could get a random number by grabbing the millisecond of the current time.
Sure, but it wouldn't be "truly" random (nothing is actually random, they just appear to be because of the complexity of the process, or number of variables involved).
EDIT: @James:
You should only call srand once in your program.
I'm thinking there can be something like, check the memory of a random process and rand() % int memory size, would that be possible?
Sure, but exactly how many processes do you expect to run on the system. What if you need to generate millions of numbers?
What firedraco was stalking about, by the way, was that, among a few other things, the intervals between clicks of a Geiger counter are considered truly random. Signals from the CMBR are also considered random.
Pure software random number generators are actually pseudo-random number generators (PRNG), because their behavior is only seemingly random.