🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #23168

Misuse of random number generators

#23168
From: William H. Jefferys
Date: Sat, 26 Dec 1987 14:50
32 lines
1666 bytes
In the discussion of Chris Christensen's problem with a macro and the
random number generator, everyone seems to have missed a key point. All
the answers pointed out the problems with Chris' use of the macro, such 
as Rich Siegel's response (not to pick on Rich):

~A correct usage would be:
~
~	x = Random();
~	x = ABS(x) % 8;

Although this does correct the incorrect macro use, it leaves another
potential problem unsolved.  I believe that the random number
generator is of the multiplicative congruential type, and that
the low order bits of such a generator are not guaranteed to give 
a very good approximation to a sequence of random numbers. Only the 
high order bits can be relied upon as a good approximation to a random
sequence.  Reduction modulo n, or (a variation) ANDing with a low-bit 
mask uses only the low order bits and may give a poor sequence. It 
would be much better to use a shift to capture the high order bits.

Thus if Random() is supplying bit patterns that fill up a longint, 
the best way to get the desired sequence is

	x = Random() >> 24;
	x = ABS(x);

Bill Jefferys
-- 
Glend.	I can call spirits from the vasty deep.
Hot.	Why, so can I, or so can any man; But will they come when you
	do call for them?    --  Henry IV Pt. I, III, i, 53
Technical Details
Message-ID: <2337@utastro.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!ut-sally!utastro!bill

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!ut-sally!utastro!bill
From: bill@utastro.UUCP (William H. Jefferys)
Newsgroups: comp.sys.mac
Subject: Misuse of random number generators
Message-ID: <2337@utastro.UUCP>
Date: 26 Dec 87 14:50:51 GMT
Organization: U. Texas, Astronomy, Austin, TX
Lines: 32
Keywords: random numbers, multiplicative congruential generators