simple pseudo-random number generator
Oct. 17th, 2025 11:26 pmFound a really interesting pseudo-random number generator that simulates the roll of six-sided dice. It was on the Wikipedia page for the TI-57 Texas Instruments programmable calculator. (It was my first computer. I still use an emulator of the TI-57 on my Android smartphone from time to time.)
π (pi) + RCL 0 = yˣ 8 - Int = STO 0 x (multiply) 6 + 1 = Int R/S (stop and start) RST (reset back to step 00)I rewrote it as an awk one-liner:
awk 'BEGIN{
pi = 3.14159265358979323846264338327950 ;
for (n=0;n<20;n++){
a=pi+b ; a=a**8 ; b= a-int(a) ; a=b*6+1 ;
printf int(a) " "
}
print ""
}'
Its output looked a bit biased to me so I wrote a quick check to see how frequently the different numbers come up in 2,000 rolls:
awk 'BEGIN{
pi = 3.14159265358979323846264338327950 ;
for (n=0;n<2000;n++){
a=pi+b ; a=a**8 ; b= a-int(a) ; a=b*6+1 ; c[int(a)]++
}
print c[1], c[2], c[3], c[4], c[5], c[6]
}'
Surpisingly even spread:
354 316 346 327 331 326