delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/29/18:00:40

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Srandom()
Date: Sun, 29 Mar 1998 17:51:44 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 53
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <351ED080.30D3A2@cornell.edu>
References: <6fku51$909 AT freenet-news DOT carleton DOT ca> <351E8C01 DOT 69BF AT cs DOT com>
NNTP-Posting-Host: cu-dialup-0721.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

John M. Aldrich wrote:
> 
> Paul Derbyshire wrote:
> >
> > How quickly does srandom() in DJGPP's libc execute? Would an added
> > srandom() before every random() in a program that uses random()
> > extensively cause a noticeable slowdown? Reason I ask is because 
> > something like that might be necessary to make a threadsafe random 
> > number generator class so that each random number generator instance 
> > can be seeded independently and give consistent results.
> 
> I think I understand what you're saying.  However, calling srandom()
> before each call to random() is a nearly foolproof way to _not_ 
> generate a random sequence of numbers. 

i think what he has in mind is more like

/* untested code */
#include <stdlib.h>

class CMyRandom
{
  private :
    int last_value;

  public  :
    CMyRandom()
    {
      last_value = random();
    }

    CMyRandom(int seed)
    {
      last_value = seed;
    }

    int value(void)
    {
      srandom(last_value);
      last_value = random();
      return last_value;
    }
};

i don't think the overhead of srandom() would be substantial.
-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


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