Skip to content

Commit 286ead4

Browse files
author
v01dxyz
committed
Obsequi: Use ANSI C LCG instead of random() for g_zobrist init
musl implements random() differently than glibc. The output of the program is thus dependent on this implementation detail and could differ between platforms. To remediate that, we replace it by a very simple PRNG (ANSI C LCG). Warning: [^1] indicates this PRNG have quite a poor LSB randomness. [^1]: Entacher, Karl. (1999). A Collection of Selected Pseudorandom Number Generators With Linear Structures. Fixes llvm/llvm-project#94048
1 parent b6d9197 commit 286ead4

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

MultiSource/Applications/obsequi/Obsequi.reference_output

+13-13
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ alpha 0, beta 5000.
136136
cutoffs depth 1: (56) 0 - 0 0 0 0 0 >0.
137137
The value is -5 at a depth of 1.
138138
Nodes: 56.
139-
Move (2,1), value 5000: 2,023,301.
139+
Move (2,1), value 5000: 2,023,432.
140140
alpha -5000, beta 5000.
141141
Winner found: 5000.
142-
1356 2450 1316053 104829.
142+
1356 2449 1316027 104839.
143143

144144
cutoffs depth 1: (1) 0 - 0 0 0 0 0 >0.
145145
cutoffs depth 2: (52) 52 - 52 0 0 0 0 >0.
@@ -148,19 +148,19 @@ cutoffs depth 4: (1263) 728 - 728 0 0 0 0 >0.
148148
cutoffs depth 5: (728) 0 - 0 0 0 0 0 >0.
149149
cutoffs depth 6: (21651) 9812 - 9810 1 1 0 0 >0.
150150
cutoffs depth 7: (9815) 3 - 2 0 0 0 1 >0.
151-
cutoffs depth 8: (160368) 38732 - 38714 14 4 0 0 >0.
152-
cutoffs depth 9: (38807) 50 - 39 6 5 0 0 >0.
153-
cutoffs depth 10: (631941) 86758 - 86673 52 10 2 2 >19.
154-
cutoffs depth 11: (87924) 775 - 634 85 19 21 10 >6.
155-
cutoffs depth 12: (771767) 55353 - 54840 256 82 15 64 >96.
156-
cutoffs depth 13: (64920) 3921 - 3389 387 124 16 5 >0.
157-
cutoffs depth 14: (187771) 7691 - 6649 766 123 44 105 >4.
158-
cutoffs depth 15: (24493) 3183 - 2950 210 13 7 3 >0.
159-
cutoffs depth 16: (14596) 1814 - 1786 26 0 0 2 >0.
160-
cutoffs depth 17: (5052) 559 - 523 33 3 0 0 >0.
151+
cutoffs depth 8: (160464) 38725 - 38707 14 4 0 0 >0.
152+
cutoffs depth 9: (38800) 50 - 39 6 5 0 0 >0.
153+
cutoffs depth 10: (631893) 86794 - 86709 52 10 2 2 >19.
154+
cutoffs depth 11: (87960) 775 - 634 85 19 21 10 >6.
155+
cutoffs depth 12: (771839) 55370 - 54856 257 82 15 64 >96.
156+
cutoffs depth 13: (64938) 3921 - 3389 387 124 16 5 >0.
157+
cutoffs depth 14: (187745) 7681 - 6638 767 123 44 105 >4.
158+
cutoffs depth 15: (24484) 3183 - 2950 210 13 7 3 >0.
159+
cutoffs depth 16: (14596) 1813 - 1785 26 0 0 2 >0.
160+
cutoffs depth 17: (5051) 559 - 523 33 3 0 0 >0.
161161
cutoffs depth 18: (1699) 181 - 167 9 5 0 0 >0.
162162
cutoffs depth 19: (326) 34 - 34 0 0 0 0 >0.
163163
cutoffs depth 20: (73) 2 - 2 0 0 0 0 >0.
164164
cutoffs depth 21: (2) 0 - 0 0 0 0 0 >0.
165-
winner V, move (1,2), nodes 2,023,301.
165+
winner V, move (1,2), nodes 2,023,432.
166166
exit 0

MultiSource/Applications/obsequi/init.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ init__real_count(s32bit player)
4949
}
5050
}
5151

52+
static s32bit ansi_c_lcg(s32bit x) {
53+
return (1103515245*x + 12345) & 0x7fffffff;
54+
}
55+
5256
extern void
5357
initialize_solver()
5458
{
@@ -60,10 +64,11 @@ initialize_solver()
6064
g_trans_table = calloc(HASHSIZE,sizeof(Hash_Entry));
6165

6266
// initialize zobrist values
63-
srandom(1);
67+
s32bit r = 1;
6468
for(i=1; i<31; i++) {
6569
for(j=1; j<31; j++) {
66-
g_zobrist[i][j] = random() & HASHMASK;
70+
r = ansi_c_lcg(r);
71+
g_zobrist[i][j] = r & HASHMASK;
6772
}
6873
}
6974

0 commit comments

Comments
 (0)