Article View: comp.os.msdos.programmer
Article #3826Re: Random Number Generator
From: Jerzy Tarasiuk
Date: Fri, 16 Oct 1992 17:36
Date: Fri, 16 Oct 1992 17:36
25 lines
2093 bytes
2093 bytes
>>>>> On 14 Oct 92 16:04:17 GMT, fulcher@doc.crd.ge.com (Karen M. Fulcher Scholz) said:
Karen> I am looking for a random number generator for a project that I am
Karen> working on. The project is going to be written in Microsoft C and
Karen> I would like to be able to call this random number generator from
Karen> my program (similar to calling IMSL routines -- unfortunately C/STAT
Karen> from IMSL is not available for the pc). Any suggestions would be
Few years ago one of my colleages told me about an idea how to make
very good pseudo-random number generator. Need use array (of long
integers for example) and to generate a "random" number need take
one number from the array, XOR it with number few positions further
(the result of XOR must be stored in array) and advance index from
which number is taken. A program in C is probably shorter:
long rtable[RTSIZE];
int rtind=0;
long rand()
{ return rtable[rtind=(rtind+1)%RTSIZE]^=rtable[(rtind+RTSHIFT)%RTSIZE]; }
It has a good chance to have a period (2 to RTSIZE)-1 and it can be
verified if the value (2 to RTSIZE)-1 is a prime number - just check
initial table is restored after this number of calls! (indirectly)
Some care must be taken about setting initial table to avoid all
zeros on any bit position or correlations between bits (a way to
avoid it is set any non-zero on bit 0, compute what will be after
2 to RTSIZE-5 calls and use this pattern for bit 1, and so on).
Recommended value of RTSIZE is between 100 and 150.
Technical Details
Message-ID:
<JT.92Oct16183601@fizyk1.fuw.edu.pl>Path:
arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!pacbell.com!sgiblab!swrinde!gatech!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!mcsun!sunic!fuw.edu.pl!cocos!jtReferences:
<1992Oct14.160417.29010@crd.ge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!pacbell.com!sgiblab!swrinde!gatech!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!mcsun!sunic!fuw.edu.pl!cocos!jt From: jt@fuw.edu.pl (Jerzy Tarasiuk) Newsgroups: comp.os.msdos.programmer Subject: Re: Random Number Generator Message-ID: <JT.92Oct16183601@fizyk1.fuw.edu.pl> Date: 16 Oct 92 17:36:01 GMT References: <1992Oct14.160417.29010@crd.ge.com> Sender: news@fuw.edu.pl Organization: Warsaw University Physics Dept. Lines: 25 In-Reply-To: fulcher@doc.crd.ge.com's message of 14 Oct 92 16:04:17 GMT Nntp-Posting-Host: fizyk1