Advertisement

random numbers in DJGPP

Started by December 21, 1999 12:48 AM
1 comment, last by GameDev.net 24 years, 11 months ago
You have to seed the random number generator with your clocks current milliseconds. That should give you a random enough number.
William Reiach - Human Extrodinaire

Marlene and Me


I know how the random(); function works but it generates the same numbers everytime you compile/run the program. Does anybody know if there is such a randomize() function in DJGPP too and how you could use it since I know DJGPP's Help is talking about initstate(unsigned seed, char *arg_state, int n) but I have no clue how to use that!

Thanks in advance,

-- Paul

Advertisement
you should actually use the rand() function because it's more portable. to get the best possible random numbers (they are never truly random), you have to seed the random number generator every time the program starts. to do this #include . then somewhere at the beginning of your program, insert this: srand(time(NULL)) ;
this will seed the random number generator with the number of seconds (milliseconds maybe?)elapsed since midnight. this way your program will come up with different random number every time you run it.

------------------
-Justin

-Justin Whitejowhite@bigfoot.comAIM: Just6979www.bigfoot.com/~jowhite"To infinity and beyond!" -Buzz Lightyear"I can only show you the door. You must choose to go through it." -Morpheus"Your mind is like a parachute. It works best when open." -Anonymous"I know Kung-fu." -Neo"Ignorance is bliss" -Cihper"My name...is Neo!" -Neo

This topic is closed to new replies.

Advertisement