![]() |
Zufallszahlenproblem
Hallo, ich habe ein Problem mit Zufallszahlen! Hier ein kleiner Abschnitt aus dem Code:
Delphi-Quellcode:
Ich bekomme jetzt aber immer für jede der 4 Variablen die gleiche Zufallszahl. Da Delphi ja für Zufallszahlen die Uhr zu Hilfe nimmer, habe ich es schon zwischen den einzelnen Abschnitten mit Sleep probiert, aber es will nicht gehen! Wie kann ich das machen? Danke!
randomize;
aktie1 := random(200) + 1; label2.Caption := IntTostr(aktie1) + ' €'; aktie2 := random(200) + 1; label5.Caption := IntTostr(aktie1) + ' €'; aktie3 := random(200) + 1; label8.Caption := IntTostr(aktie1) + ' €'; aktie4 := random(200) + 1; label11.Caption := IntTostr(aktie1) + ' €'; |
Re: Zufallszahlenproblem
Hallo,
Probiers mal so :-)
Delphi-Quellcode:
Hab´s auch erst beim 2. mal hinsehen gemerkt...
randomize;
aktie1 := random(200) + 1; label2.Caption := IntTostr(aktie1) + ' €'; aktie2 := random(200) + 1; label5.Caption := IntTostr(aktie2) + ' €'; aktie3 := random(200) + 1; label8.Caption := IntTostr(aktie3) + ' €'; aktie4 := random(200) + 1; label11.Caption := IntTostr(aktie4) + ' €'; Schöne Grüße Markus |
Re: Zufallszahlenproblem
Du hast beim kopieren vergessen die zuweisung auf deine Label zu ändern!
Sonst hättest du auch überall andere Zahlen! Zitat:
aktie1 := random(200) + 1; label2.Caption := IntTostr(aktie1) + ' €'; aktie2 := random(200) + 1; label5.Caption := IntTostr(aktie2) + ' €'; aktie3 := random(200) + 1; label8.Caption := IntTostr(aktie3) + ' €'; aktie4 := random(200) + 1; label11.Caption := IntTostr(aktie4) + ' €'; da war wohl jemand schneller! |
Re: Zufallszahlenproblem
Hai Uceo,
von der Funktion her ist es eigentlich richt. Wichtig ist nur das randomize nur EINMAL im Programm aufgerufen wird. Ab besten im .OnCreate der MainForm. Uff... das mit den Falschen Namen habe ich doch glatt übersehen :oops: |
Re: Zufallszahlenproblem
O_o! Das hatte ich ganz übersehen! Ich suche jetzt nun schon ewig, aber vielen dank an euch alle!
|
Re: Zufallszahlenproblem
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:39 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