I've recently been reading about the history of pseudo-random number generators, and I've found RANDU to be particularly fascinating.
So tonight for fun, I implemented RANDU in BBC BASIC and made this little graphics demo with it:
Code: Select all
randu_seed%%=1
n%=1600
DIM p(n%,2), c(n%)
FOR i%=0 TO n%
FOR j%=0 TO 2
p(i%,j%) = (FNrandu-0.5)*700
NEXT
c(i%)=1+FNrandu*14
NEXT
DIM r(2,2), r2(2,2), a(n%,2)
MODE 8
OFF
ORIGIN 640,512
*refresh off
REPEAT
MOUSE X%,Y%,B%
a=X%/640*PI
a2=Y%/-512*PI
r(0,0)=COSa: r(2,0)=SINa: r(1,1)=1.0: r(0,2)=-SINa: r(2,2)=COSa
r2(0,0)=1.0: r2(1,1)=COSa2: r2(2,1)=-SINa2: r2(1,2)=SINa2: r2(2,2)=COSa2
a() = p() . r()
a() = a() . r2()
CLG
FOR i%=0 TO n%
GCOL 0, c(i%)
PLOT 69, a(i%,0), a(i%,1)
NEXT
*refresh
WAIT 1
UNTIL FALSE
END
DEF FNrandu
randu_seed%% = (65539 * randu_seed%%) MOD 2147483648
= randu_seed%% / 2147483648
The demo generates a number of points in 3D space, and lets you rotate them around by moving the mouse.
From some angles it looks like the points are dispersed randomly... but then when you move the perspective a bit, you'll find that the points all lie on 15 planes. Fascinating!
I've really enjoyed looking into this fascinating and amazing function and learning about the history of it tonight. I hope you will too.
Here is the wikipedia which is a very good read: https://en.wikipedia.org/wiki/RANDU
Regards,
PM