Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!vic.news.telstra.net!act.news.telstra.net!imci3!imci4!newsfeed.internetmci.com!iol!tank.news.pipex.net!pipex!dispatch.news.demon.net!demon!sunsite.doc.ic.ac.uk!yama.mcc.ac.uk!rmcs.cranfield.ac.uk!warner
From: warner@rmcs.cranfield.ac.uk (Alistair (Joe) Warner)
Newsgroups: comp.os.linux.development.system,comp.bugs.4bsd
Subject: Random Number Generation with Linux (using BSD) and BSD
Date: 28 Mar 96 15:45:20 +0100
Organization: Royal Military College of Science, Cranfield University
Lines: 57
Message-ID: <1996Mar28.154520.1@rmcs.cranfield.ac.uk>
NNTP-Posting-Host: gw.rmcs.cranfield.ac.uk
Xref: euryale.cc.adfa.oz.au comp.os.linux.development.system:20427 comp.bugs.4bsd:2097
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
"random.c 5.5 (Berkeley) 7/6/88".
I pulled random.c from my local BSD ftp mirror (src.doc.ic.ac.uk) and am
assuming that this is the code used by SunOS (the random number table is
the same so I have taken that as a good indication). I note that its
version is
"random.c 5.9 (Berkeley) 2/23/91"
As I might have expected these files contain different random number
tables but I ought to be able to make the RNG's equivalent by using
initstate with the appropriate table.
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?
For what it is worth I think that the Linux version has a typo since
__random uses
state[0] = ((state[0] * 1103515245) + 12345) & LONG_MAX;
in its TYPE_0 RNG which is consistent with the BSD rand function - a
TYPE_0 RNG.
Any authorative answers would be greatly appreciated!
Thanks in advance
--
+--------------------------------------+-----------------------------------+
| Alistair Warner, Project Engineer | Domain Dynamics Limited |
| | Cranfield University (RMCS) |
| Email: warner@rmcs.cranfield.ac.uk | Shrivenham |
| Phone: +44 1793 785 491 | SWINDON SN6 8LA |
| Fax: +44 1793 782 008 | U.K. |
+--------------------------------------+-----------------------------------+