@@ -26,7 +26,7 @@ TGenerator = class(TObject)
26
26
procedure BuildStationNames ;
27
27
function GenerateProgressBar (APBPosition, APBMax, APBWIdth: Integer;
28
28
AFileSize: Int64; ATimeElapsed: TDateTime): String;
29
- function Rng1brc (Range: longint ): longint ;
29
+ function Rng1brc (Range: Integer ): Integer ;
30
30
protected
31
31
public
32
32
constructor Create(AInputFile, AOutputFile: String; ALineCount: Int64);
@@ -180,11 +180,11 @@ procedure TGenerator.Generate;
180
180
var
181
181
index, progressCount, progressBatch: Integer;
182
182
stationId, randomTemp: Integer;
183
- randomTempStr: String[ 4 ] ;
183
+ randomTempWord: Word ;
184
184
outputFileStream: TFileStream;
185
185
chunkLine, randomTempFinal: Utf8String;
186
186
stationArray, temperatureArray: TStringArray;
187
- LenStationArray, LenTemperatureArray: Array of Integer ;
187
+ stationTempOffsetArray, stationTempRangeArray, LenStationArray, LenTemperatureArray: Array of Word ;
188
188
chunkCount, chunkLen, stationsCount, temperaturesCount: Integer;
189
189
start: TDateTime;
190
190
begin
@@ -202,38 +202,28 @@ procedure TGenerator.Generate;
202
202
// This is all paweld magic:
203
203
// From here
204
204
// based on code @domasz from lazarus forum, github: PascalVault
205
+ temperaturesCount := 1999 ;
205
206
stationsCount := FStationNames.count;
206
207
SetLength(stationArray, stationsCount);
207
208
SetLength(LenStationArray, stationsCount);
209
+ SetLength(stationTempOffsetArray, stationsCount);
210
+ SetLength(stationTempRangeArray, stationsCount);
208
211
for index := 0 to stationsCount - 1 do
209
212
begin
210
213
stationArray[index] := FStationNames[index] + ' ;' ;
211
214
LenStationArray[index] := Length(stationArray[index]);
215
+ stationTempRangeArray[index] := Rng1brc(501 ) + 350 ;
216
+ stationTempOffsetArray[index] := Rng1brc(temperaturesCount - stationTempRangeArray[index]);
212
217
end ;
213
218
214
219
temperaturesCount := 1999 ;
215
220
SetLength(temperatureArray, temperaturesCount);
216
221
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
220
223
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]);
237
227
end ;
238
228
239
229
chunkCount := chunkBatch;
@@ -249,13 +239,14 @@ procedure TGenerator.Generate;
249
239
for index := 1 to FLineCount do
250
240
begin
251
241
stationId := Rng1brc(stationsCount);
252
- randomTemp := Rng1brc(temperaturesCount);
242
+ randomTemp := stationTempOffsetArray[stationId] + Rng1brc(stationTempRangeArray[stationId]);
243
+ randomTempWord := randomTemp and $FFFF;
253
244
Move(stationArray[stationId][1 ], chunkLine[chunkLen + 1 ],
254
245
LenStationArray[stationId]);
255
246
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 ]);
259
250
260
251
Dec(chunkCount);
261
252
if chunkCount = 0 then
0 commit comments