From: "A. Sinan Unur" 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 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/