Mail Archives: djgpp/1997/03/07/13:47:45
Shawn Betts (hotpulp AT netidea DOT com) wrote:
: I was working with rand() and random() and noticed that there aren't any
: randomize functions that I could find for DJGPP. I found srand() and
: srandom() but they require a random seed. I would like a randomized timer
: function like so many other compilers I have seen (QBASIC, TURBO PASCAL 6.0,
: TURBO C++ 3.0). Does anyone know if I've over looked something. If I haven't
: how do I make a randomizer function?
You simply pass an unknown value to srand() (to randomise rand()) or
srandom() (to randomise random()), for example the current time of day.
Try this:
#define randomize srandom(time(NULL))
#define randize srand(time(NULL))
then write `randomize;' to randomise the random() function, or `randize;'
to randomise the rand() function.
Note that rand() is portable, while random() is not; however, random()
returns numbers which are more random; for example, (rand()&3) apparently
isn't as random as (random()&3). Using random(), whatever value you & or %
it with, you'll get more unpredictable results. Apparently.
--
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.
- Raw text -