From 045c04e2bcd7a5660888650bab0559e854a4e270 Mon Sep 17 00:00:00 2001 From: paweld Date: Tue, 5 Mar 2024 19:17:15 +0100 Subject: [PATCH 1/2] improvement of the rng function the previous version gave identical results only in the same processor "session" --- generator/Common/generate.common.pas | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/generator/Common/generate.common.pas b/generator/Common/generate.common.pas index 5a9bf20..fdde3da 100644 --- a/generator/Common/generate.common.pas +++ b/generator/Common/generate.common.pas @@ -52,7 +52,7 @@ implementation ; const - cSeed: LongInt = 46668267; // '1BRC' in ASCII + cSeed = 46668267; // '1BRC' in ASCII linesPercent = 10; stationsCapacity = 50000; chunkBatch = 10000; @@ -161,13 +161,13 @@ function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize function TGenerator.Rng1brc(Range: longint): longint; const - state: Array [0..1] of DWord = (46668267, 7266); + state: Array [0..1] of DWord = (cSeed, 7266); var s0, s1, s2: DWord; begin s0 := state[0]; s1 := state[1] xor s0; - s2 := RolDWord(s1 * 3, 5) * 7; + s2 := ((s1 * 3) xor 5) * 7; Result := longint(Int64(s2 * range) shr 32); state[0] := s2; state[1] := s0 xor (s1 shl 9); @@ -186,10 +186,6 @@ procedure TGenerator.Generate; chunkCount, chunkLen, stationsCount, temperaturesCount: Integer; start: TDateTime; begin - // Randomize sets this variable depending on the current time - // We just set it to our own value - RandSeed := cSeed; - // Build list of station names BuildStationNames; From 698fd4670cb256a557bc16c8049bb575edf1a80a Mon Sep 17 00:00:00 2001 From: paweld Date: Tue, 5 Mar 2024 19:43:17 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Tekst=20=C5=BAr=C3=B3d=C5=82owy=20=E2=80=8B?= =?UTF-8?q?=2053=20/=205=20000=20Wyniki=20t=C5=82umaczenia=20T=C5=82umacze?= =?UTF-8?q?nie=20changes=20allowing=20compilation=20of=20the=20rng=20funct?= =?UTF-8?q?ion=20in=20Delphi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/Common/generate.common.pas | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/generator/Common/generate.common.pas b/generator/Common/generate.common.pas index fdde3da..81704f9 100644 --- a/generator/Common/generate.common.pas +++ b/generator/Common/generate.common.pas @@ -17,6 +17,7 @@ interface TGenerator = class(TObject) private + rndState: Array [0..1] of Cardinal; FInputFile: String; FOutPutFile: String; FLineCount: Int64; @@ -160,17 +161,15 @@ function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize end; function TGenerator.Rng1brc(Range: longint): longint; -const - state: Array [0..1] of DWord = (cSeed, 7266); var - s0, s1, s2: DWord; + s0, s1, s2: Cardinal; begin - s0 := state[0]; - s1 := state[1] xor s0; + s0 := rndState[0]; + s1 := rndState[1] xor s0; s2 := ((s1 * 3) xor 5) * 7; Result := longint(Int64(s2 * range) shr 32); - state[0] := s2; - state[1] := s0 xor (s1 shl 9); + rndState[0] := s2; + rndState[1] := s0 xor (s1 shl 9); end; procedure TGenerator.Generate; @@ -186,6 +185,9 @@ procedure TGenerator.Generate; chunkCount, chunkLen, stationsCount, temperaturesCount: Integer; start: TDateTime; begin + //random init + rndState[0] := cSeed; + rndState[1] := 7266; // Build list of station names BuildStationNames;