![]() |
Re: Random ohne doppelte Zahlen
Hallo,
hier würde sich auch ein Array vom Typ Boolean anbieten. Pseudocode:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var My_LisboxIndex: Array[1..(Listbox.Count)] of Boolean; i, z: Integer; begin for i:= 1 to (Listbox.Count) do My_LisboxIndex[i]:=false; for i:=1 to (Listbox.Count) do begin repeat z:=random(Listbox.Count) + 1 until My_LisboxIndex[z] = false; My_LisboxIndex[z]:=true; end; for i:=1 to (Listbox.Count)] do if My_LisboxIndex[i] then Listbox.TopIndex := (i); //oder halt irgendwas anderes an dieser Stelle tun... end; |
Re: Random ohne doppelte Zahlen
Ich gehe mal davon aus, daß wir 12 Namen haben, die in labelededit1..12 stehen. Dann sähe eine Lösung (analog des Vorschlags von Z4ppy) so aus:
Delphi-Quellcode:
var
list: TStringList; I, N: Integer; begin list := TStringList.Create; try { Liste mit den Einträgen füllen } list.Add(labelededit1.Text); ... list.Add(labelededit12.Text); N := list.Count; for I:=1 to N do begin if list.Count < 2 then N := Random(list.Count) else N := 0; memo1.Lines.Add(IntToStr(I) + ':' + list[N]); list.Delete(N); end; Assert(list.Count = 0, 'Liste nicht leer!'); finally list.Free; end; end; |
Re: Random ohne doppelte Zahlen
Den Code verstehe ich nicht.
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz