Good xorshift, Bad xorshift
- Marsaglia's xorshift : y^=y<<a; y^=y>>b; y^=y<<c;
Tested by FreeBASIC simple graphical test program
- 32bit xorshift good parameters
- (a, b, c)32bit = (3, 13, 7), (5, 13, 6), (9, 11, 19)
- 64bit xorshift good parameters
- (a, b, c)64bit = (3, 35, 14), (3, 43, 11), (4, 35, 21), (4, 37, 11), (5, 41, 20),
(6, 27, 7), (7, 23, 8), (7, 33, 8), (8, 31, 17), (9, 21, 11), (9, 27, 10),
(9, 29, 12), (11, 29, 14), (11, 31, 18) . . . etc
FreeBASIC graphical xorshift test program |
- Test paramters are (a, b, c) and shft
/' (c) 2021 cepstrum.co.jp '/
' FreeBASIC GUI program
' >fbc -s gui
'--------------------------------------------------------------------------
' xorshift random number generator
function uint_xorshift(a as uinteger, b as uinteger, c as uinteger) as uinteger<32>
static r as uinteger<32> = &Hffffffff
r=r xor (r shl a)
r=r xor (r shr b)
r=r xor (r shl c)
return r
end function
'--------------------------------------------------------------------------
dim x as uinteger
dim y as uinteger
dim dotc as uinteger
dim a as uinteger = 5
dim b as uinteger = 17
dim c as uinteger = 13
dim shft as uinteger = 1
screenres 1024, 1024
sleep 300
while inkey$<>""
wend
while inkey$=""
x =(uint_xorshift(a, b, c) shr shft) mod 1024
y =(uint_xorshift(a, b, c) shr shft) mod 1024
dotc=(uint_xorshift(a, b, c) shr shft) mod 64
line (x, y)-(x, y), dotc
wend
- Graph title "xorshift_a_b_c" contain parameter (a, b, c).
- shft=0
Good/O.K
Bad/N.G.
xorshift_3_13_7.exe
xorshift_1_5_16.exe xorshift_1_19_3.exe xorshift_1_21_20.exe xorshift_1_27_27.exe xorshift_2_7_7.exe xorshift_2_15_25.exe xorshift_5_7_22.exe xorshift_5_17_13.exe xorshift_9_5_1.exe