www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/10/23:16:38

From: cat AT animal DOT u-net DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random numbers?
Message-ID: <3851b4cb.79393432@news.f9.net.uk>
References: <384F1689 DOT B435CCDF AT localnet DOT com> <83wvqo3dj0 DOT fsf AT mercury DOT st DOT hmc DOT edu>
X-Newsreader: Forte Free Agent 1.11/32.235
Lines: 23
Date: Sat, 11 Dec 1999 02:24:04 GMT
NNTP-Posting-Host: 212.56.123.170
X-Complaints-To: abuse AT plus DOT net DOT uk
X-Trace: wards 944880361 212.56.123.170 (Sat, 11 Dec 1999 02:46:01 GMT)
NNTP-Posting-Date: Sat, 11 Dec 1999 02:46:01 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On 08 Dec 1999 21:10:27 -0800, Nate Eldredge <neldredge AT hmc DOT edu> wrote:

>Mark Simmons <zack97 AT localnet DOT com> writes:
>
>> How do I get a number that will be psuedo random?  time(null) % max
>> doesn't work because the numbers need to be read in quick succession and
>> it simply produces a 1,2,3,4,5,6,7,8,9...0,1,2.... etc. pattern.. So,
>> how do I get a number that seems sort of random with a variable max?
>
>Read about `rand' in the documentation.  Don't forget to `srand';
>`time(NULL)' makes a good seed.
>
>-- 
>
>Nate Eldredge
>neldredge AT hmc DOT edu

    Try calling time() several times. Each time use the seconds value as
the count for a loop. loop  for (;0<seconds--;rand());.  This shifts the
sequence along a few
steps, and iterating this loop a few hundred times should randomise
reasonably well.

- Raw text -


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