www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/07/13:47:45

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: a randomize function for DJGPP?
Date: 6 Mar 1997 04:20:12 GMT
Organization: Oxford University
Lines: 26
Message-ID: <5flgls$feh@news.ox.ac.uk>
References: <5flbpp$m74 AT nr1 DOT ottawa DOT istar DOT net>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019