@@ -26,7 +26,7 @@ TGenerator = class(TObject)
2626 procedure BuildStationNames ;
2727 function GenerateProgressBar (APBPosition, APBMax, APBWIdth: Integer;
2828 AFileSize: Int64; ATimeElapsed: TDateTime): String;
29- function Rng1brc (Range: longint ): longint ;
29+ function Rng1brc (Range: Integer ): Integer ;
3030 protected
3131 public
3232 constructor Create(AInputFile, AOutputFile: String; ALineCount: Int64);
@@ -180,11 +180,11 @@ procedure TGenerator.Generate;
180180var
181181 index, progressCount, progressBatch: Integer;
182182 stationId, randomTemp: Integer;
183- randomTempStr: String[ 4 ] ;
183+ randomTempWord: Word ;
184184 outputFileStream: TFileStream;
185185 chunkLine, randomTempFinal: Utf8String;
186186 stationArray, temperatureArray: TStringArray;
187- LenStationArray, LenTemperatureArray: Array of Integer ;
187+ stationTempOffsetArray, stationTempRangeArray, LenStationArray, LenTemperatureArray: Array of Word ;
188188 chunkCount, chunkLen, stationsCount, temperaturesCount: Integer;
189189 start: TDateTime;
190190begin
@@ -202,38 +202,28 @@ procedure TGenerator.Generate;
202202 // This is all paweld magic:
203203 // From here
204204 // based on code @domasz from lazarus forum, github: PascalVault
205+ temperaturesCount := 1999 ;
205206 stationsCount := FStationNames.count;
206207 SetLength(stationArray, stationsCount);
207208 SetLength(LenStationArray, stationsCount);
209+ SetLength(stationTempOffsetArray, stationsCount);
210+ SetLength(stationTempRangeArray, stationsCount);
208211 for index := 0 to stationsCount - 1 do
209212 begin
210213 stationArray[index] := FStationNames[index] + ' ;' ;
211214 LenStationArray[index] := Length(stationArray[index]);
215+ stationTempRangeArray[index] := Rng1brc(501 ) + 350 ;
216+ stationTempOffsetArray[index] := Rng1brc(temperaturesCount - stationTempRangeArray[index]);
212217 end ;
213218
214219 temperaturesCount := 1999 ;
215220 SetLength(temperatureArray, temperaturesCount);
216221 SetLength(LenTemperatureArray, temperaturesCount);
217- temperatureArray[0 ] := ' 0.0' + lineEnding;
218- LenTemperatureArray[0 ] := Length(temperatureArray[0 ]);
219- for index := 1 to 999 do
222+ for index := 0 to High(temperatureArray) do
220223 begin
221- randomTempStr := IntToStr(index);
222- case Ord(randomTempStr[0 ]) of
223- 1 :
224- randomTempFinal := ' 0.' + randomTempStr;
225- 2 :
226- randomTempFinal := randomTempStr[1 ] + ' .' + randomTempStr[2 ];
227- 3 :
228- randomTempFinal := randomTempStr[1 ] + randomTempStr[2 ] + ' .' + randomTempStr[3 ];
229- 4 :
230- randomTempFinal := randomTempStr[1 ] + randomTempStr[2 ] + randomTempStr[3 ] + ' .' +
231- randomTempStr[4 ];
232- end ;
233- temperatureArray[index * 2 - 1 ] := randomTempFinal + lineEnding;
234- LenTemperatureArray[index * 2 - 1 ] := Length(temperatureArray[index * 2 - 1 ]);
235- temperatureArray[index * 2 ] := ' -' + randomTempFinal + lineEnding;
236- LenTemperatureArray[index * 2 ] := LenTemperatureArray[index * 2 - 1 ] + 1 ;
224+ randomTempFinal := FormatFloat(' 0"."0' , index - 999 );
225+ temperatureArray[index] := randomTempFinal + lineEnding;
226+ LenTemperatureArray[index] := Length(temperatureArray[index]);
237227 end ;
238228
239229 chunkCount := chunkBatch;
@@ -249,13 +239,14 @@ procedure TGenerator.Generate;
249239 for index := 1 to FLineCount do
250240 begin
251241 stationId := Rng1brc(stationsCount);
252- randomTemp := Rng1brc(temperaturesCount);
242+ randomTemp := stationTempOffsetArray[stationId] + Rng1brc(stationTempRangeArray[stationId]);
243+ randomTempWord := randomTemp and $FFFF;
253244 Move(stationArray[stationId][1 ], chunkLine[chunkLen + 1 ],
254245 LenStationArray[stationId]);
255246 Inc(chunkLen, LenStationArray[stationId]);
256- Move(temperatureArray[randomTemp ][1 ], chunkLine[chunkLen + 1 ],
257- LenTemperatureArray[randomTemp ]);
258- Inc(chunkLen, LenTemperatureArray[randomTemp ]);
247+ Move(temperatureArray[randomTempWord ][1 ], chunkLine[chunkLen + 1 ],
248+ LenTemperatureArray[randomTempWord ]);
249+ Inc(chunkLen, LenTemperatureArray[randomTempWord ]);
259250
260251 Dec(chunkCount);
261252 if chunkCount = 0 then
0 commit comments