Autor Beitrag
Gisi
Hält's aus hier
Beiträge: 3

Win XP, Win Vista
Delphi 3
BeitragVerfasst: Mi 06.05.09 15:04 
HI!

Tjaa da das hier mein erster Post ist - und bis jetzt noch nicht wirklich aktiv im Forum geschrieben habe :D hoffe ich mal, dass ich kein Suchergebnis übersehen habe.

Ok nun zum Problem:

Ich habe vor ein einfaches Programm zur Würfel auswertung bei Beispielsweise 100 Würfen auszugeben. So weit so gut - die Anzahl der Würfe wird durch die Eingabe des Users bestimmt - die Ausgabe der Häufigkeit in Prozent der einzelnen Zahlen erfolgt in einzelnen edit feldern. jaaa blahblablub seht ihr ja dann alles :P

ICh habe das Problem, dass nur beim Schrittweisen ausführen des Programms auch wirklich zufällige Ergebnisse ausgegeben werden- Beim Ausführen des Programms und der Eingabe der Anzahl der zu würfelnden Zahlen bekomme ich die Anzahl der Würfe +1 in einem der 6 ausgabe felder... ich hoffe ihr habt das problem verstanden. Ich verstehs nämlich nicht?!

Vielen Dank schonmal im Voraus! --- btw Delphi3 ---

ausblenden volle Höhe Delphi-Quelltext
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:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    EEingabe: TEdit;
    Ea: TEdit;
    Eb: TEdit;
    Ec: TEdit;
    Ed: TEdit;
    Ee: TEdit;
    Ef: TEdit;
    BWuerfeln: TButton;
    procedure BWuerfelnClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.BWuerfelnClick(Sender: TObject);
var a,b,c,d,e,f : real;
i, eingabe, zufall : integer;
begin
  a:=0;
  b:=0;
  c:=0;
  d:=0;
  e:=0;
  f:=0;
  zufall:=0;
  eingabe:=StrToInt(EEingabe.Text);
  for i:=0 to eingabe do
  begin
    randomize;
    zufall:=random(6)+1;
    if zufall = 1 then
      a:=a+1
      else
    if zufall = 2 then
      b:=b+1
      else
    if zufall = 3 then
      c:=c+1
      else
    if zufall = 4 then
      d:=d+1
      else
    if zufall = 5 then
      e:=e+1
      else
    if zufall = 6 then
      f:=f+1
      else
      f:=f;
  end;
  a:=a/eingabe;
  b:=b/eingabe;
  c:=c/eingabe;
  d:=d/eingabe;
  e:=e/eingabe;
  f:=f/eingabe;
  Ea.Text:=FloatToStr(a);
  Eb.Text:=FloatToStr(b);
  Ec.Text:=FloatToStr(c);
  Ed.Text:=FloatToStr(d);
  Ee.Text:=FloatToStr(e);
  Ef.Text:=FloatToStr(f);
end;

end.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 06.05.09 15:17 
Rufe randomize nur einmal auf im FormCreate.
Gisi Threadstarter
Hält's aus hier
Beiträge: 3

Win XP, Win Vista
Delphi 3
BeitragVerfasst: Mi 06.05.09 15:18 
Cool - herzlichen Dank!

Es funktioniert nun, es würde mich dennoch interessieren, warum ich es nicht in die Schleife packen darf=?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 06.05.09 15:20 
Steht hier im Forum bereits häufig genug erklärt. Kurzfassung: Randomize ist von der Urzeit abhängig; durch die Schleife erfolgt der Aufruf aber so zügig, dass immer noch intern die gleiche Zeit verwendet wird --> Gleiche Zufallskette.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Gisi Threadstarter
Hält's aus hier
Beiträge: 3

Win XP, Win Vista
Delphi 3
BeitragVerfasst: Mi 06.05.09 15:21 
Alles klar ;)

Vielen Dank nochmal!