Na,
du verstehst nicht, ich meinte du kannst die Anzahl records ermitteln,
das wird dann die Größe des Bit-Arrays. Dann kriegst du per Random() eine
Position (Zahl von 1 bis Anzahl Records). Und jedes Mal, wenn du eine Position bekommst,
machst du folgendes: BitArray.Bits[Position-1] := True;
So zum Beispiel:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
| procedure TForm1.Button1Click(Sender: TObject); var Bits: TBits; IntFile: file of Integer; CurrentInt: Integer; RecordCount: Cardinal; Position: Integer; begin Bits := TBits.Create; try FileMode := fmOpenRead; AssignFile(IntFile, 'C:\Test.bin'); Reset(IntFile); RecordCount := FileSize(IntFile); Bits.Size := RecordCount;
Randomize;
while Bits.OpenBit <> Bits.Size do begin Position := Random(RecordCount); if not Bits[Position] then begin Seek(IntFile, Position); Read(IntFile, CurrentInt);
Bits[Position] := True; end; end;
CloseFile(IntFile); finally Bits.Free; end; end; |
Gruß,
MrCoder