Skip to content

Commit 045c04e

Browse files
committed
improvement of the rng function
the previous version gave identical results only in the same processor "session"
1 parent fdc0832 commit 045c04e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

generator/Common/generate.common.pas

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ implementation
5252
;
5353

5454
const
55-
cSeed: LongInt = 46668267; // '1BRC' in ASCII
55+
cSeed = 46668267; // '1BRC' in ASCII
5656
linesPercent = 10;
5757
stationsCapacity = 50000;
5858
chunkBatch = 10000;
@@ -161,13 +161,13 @@ function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize
161161

162162
function TGenerator.Rng1brc(Range: longint): longint;
163163
const
164-
state: Array [0..1] of DWord = (46668267, 7266);
164+
state: Array [0..1] of DWord = (cSeed, 7266);
165165
var
166166
s0, s1, s2: DWord;
167167
begin
168168
s0 := state[0];
169169
s1 := state[1] xor s0;
170-
s2 := RolDWord(s1 * 3, 5) * 7;
170+
s2 := ((s1 * 3) xor 5) * 7;
171171
Result := longint(Int64(s2 * range) shr 32);
172172
state[0] := s2;
173173
state[1] := s0 xor (s1 shl 9);
@@ -186,10 +186,6 @@ procedure TGenerator.Generate;
186186
chunkCount, chunkLen, stationsCount, temperaturesCount: Integer;
187187
start: TDateTime;
188188
begin
189-
// Randomize sets this variable depending on the current time
190-
// We just set it to our own value
191-
RandSeed := cSeed;
192-
193189
// Build list of station names
194190
BuildStationNames;
195191

0 commit comments

Comments
 (0)