*BSD News Article 64764


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.bhp.com.au!mel.dit.csiro.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.ysu.edu!usenet.ins.cwru.edu!gatech!usenet.eel.ufl.edu!tank.news.pipex.net!pipex!dispatch.news.demon.net!demon!mail2news.demon.co.uk!knosof.demon.co.uk
From: Derek M Jones <derek@knosof.co.uk>
Newsgroups: comp.os.linux.development.system,comp.bugs.4bsd
Subject: Re: Random Number Generation with Linux (using BSD) and BSD
Date: Thu, 28 Mar 96 21:26:43 GMT
Organization: Knowledge Software Ltd
Lines: 56
Message-ID: <828048403snz@knosof.co.uk>
References: <1996Mar28.154520.1@rmcs.cranfield.ac.uk>
Reply-To: derek@knosof.co.uk
X-NNTP-Posting-Host: knosof.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.30
X-Mail2News-Path: knosof.demon.co.uk
Xref: euryale.cc.adfa.oz.au comp.os.linux.development.system:20399 comp.bugs.4bsd:2096

In article <1996Mar28.154520.1@rmcs.cranfield.ac.uk>
           warner@rmcs.cranfield.ac.uk "Alistair (Joe" writes:

> I have recently been involved in a cooperative project and the results
> have given me cause to make a comparison of srandom/random between
> Linux & SunOS.
> 
> My colleague (the one with Linux) sent me his source __random.c which
> indicates that it is based upon the Berkeley source
> 
> However, this will not work because the two files are different in the
> srandom/__srandom functions
> 
>     BSD:    state[i] = 1103515245 * state[i - 1] + 12345;
> 
>     Linux:  state[i] = 1103515145 * state[i - 1] + 12345;
>                               ^
> 
> The constant used to multiply is different - as shown.
> 
> So my questions are
> 
> 1.  Has the value of the multiplication constant above in the BSD source
>     changed between 5.5 & 5.9? 
> 
> 2.  Does the Linux version of __srandom contain a typo in the
>     multiplication constant?
> 

I would not worry about the change in digits.  Both these random number
generators are a joke.

The following

x = (171 * x) % 30269

y = (172 * y) % 30307

z = (170 * z) % 30323

rand = fmod( x / 30269.0 + y / 30307.0 + z / 30323.0, 1.0)

has lots of desirable properties.  See Algorithm 183,
Applied Statistics 1982, Vol 32 No 2

At 1000 numbers a second this function will take 880 years to repeat
the same number sequence.

derek

--
Derek M Jones                                     tel: +44 (0) 1252 520 667
Knowledge Software Ltd                          email: derek@knosof.co.uk
                                                 http://www.knosof.co.uk