delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/30/22:31:33

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Srandom
Date: Mon, 30 Mar 1998 21:52:15 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 25
Message-ID: <35205A5F.6C23@cs.com>
References: <19980330 DOT 202928 DOT 14806 DOT 0 DOT matthew DOT krause AT juno DOT com>
NNTP-Posting-Host: ppp237.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Matthew R Krause wrote:
> 
> Wouldn't using the previous random number as a seed work better? In other
> words, start with the time as a seed and generate a random number 'x'.
> Seed random with 'x' next time, and set 'x' as new seed?
> I'm not sure about this, though, and __please__ tell if I'm wrong!!

Well, sort of.  However, random(), as opposed to rand(), uses a highly
complex mathematical algorithm for generating random values, and
reseeding it each time it runs, especially if the seed is based on a
prior value of the algorithm, could theoretically produce
non-randomness.  As a practical matter, nobody has ever tested it.

Besides, the problem is that if a program fork()s itself, the child
process will inherit the parent's seed, and therefore an identical
series of random numbers.  There has to be some way to make it use a
different seed in each process.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Proud owner of what might one   |   http://www.cs.com/fighteer/   |
| day be a spectacular MUD...     |       ICQ UIN#:  7406319        |
| Plan: To make Bill Gates suffer |     HEAT User ID:  Fighteer     |
---------------------------------------------------------------------

- Raw text -


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