Mail Archives: djgpp/1997/03/05/06:33:53
>Sorry for asking that stupid question, but can anybody tell me how i can
>get random numbers from 0 to 255?
>
>Do i have to call something like a randomize timer function like in
>Borland?
>
random_number_0_to_255 = rand() % 256;
the declaration for rand() is in stdlib.h
It is usually good to seed the random number generator. Otherwise it would
create the same sequence of "random" numbers every time.
You can do it at the begining of your program for example:
time_t now;
now = time(NULL); /* or: time(&now);
srand(now);
Eyal.
- Raw text -