Skip to content

Commit 3570fd9

Browse files
authored
Merge pull request #11 from paweld/gus
improvement of the rng function
2 parents 906ee93 + 698fd46 commit 3570fd9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

generator/Common/generate.common.pas

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface
1717

1818
TGenerator = class(TObject)
1919
private
20+
rndState: Array [0..1] of Cardinal;
2021
FInputFile: String;
2122
FOutPutFile: String;
2223
FLineCount: Int64;
@@ -52,7 +53,7 @@ implementation
5253
;
5354

5455
const
55-
cSeed: LongInt = 46668267; // '1BRC' in ASCII
56+
cSeed = 46668267; // '1BRC' in ASCII
5657
linesPercent = 10;
5758
stationsCapacity = 50000;
5859
chunkBatch = 10000;
@@ -160,17 +161,15 @@ function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize
160161
end;
161162

162163
function TGenerator.Rng1brc(Range: longint): longint;
163-
const
164-
state: Array [0..1] of DWord = (46668267, 7266);
165164
var
166-
s0, s1, s2: DWord;
165+
s0, s1, s2: Cardinal;
167166
begin
168-
s0 := state[0];
169-
s1 := state[1] xor s0;
170-
s2 := RolDWord(s1 * 3, 5) * 7;
167+
s0 := rndState[0];
168+
s1 := rndState[1] xor s0;
169+
s2 := ((s1 * 3) xor 5) * 7;
171170
Result := longint(Int64(s2 * range) shr 32);
172-
state[0] := s2;
173-
state[1] := s0 xor (s1 shl 9);
171+
rndState[0] := s2;
172+
rndState[1] := s0 xor (s1 shl 9);
174173
end;
175174

176175
procedure TGenerator.Generate;
@@ -186,10 +185,9 @@ procedure TGenerator.Generate;
186185
chunkCount, chunkLen, stationsCount, temperaturesCount: Integer;
187186
start: TDateTime;
188187
begin
189-
// Randomize sets this variable depending on the current time
190-
// We just set it to our own value
191-
RandSeed := cSeed;
192-
188+
//random init
189+
rndState[0] := cSeed;
190+
rndState[1] := 7266;
193191
// Build list of station names
194192
BuildStationNames;
195193

0 commit comments

Comments
 (0)