Autor Beitrag
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mo 21.02.05 16:51 
Also:
Ich habe ien Programm geschrieben, dass die Randomfunktino auf ihre zufälligkeit untersucht.
Nun gebe ich ein, wie oft "gewürfelt" werden soll, und er gibt mir eben aus, wie oft die Zahlen vono 0-9 vorkommen.
Eingabe per edit, ausgabe per Stringgrid miti folgenden Eigenschaften:

ColCount:=3;
RowCount:=11;
FixedCols:=1;
FixedRows:=1;

Um die Funtkoni Random zu testen, verwende ich folgende PRocedure:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.BtnStartClick(Sender: TObject);
var i,zahl:integer;
begin
for i:=0 to 9 do
  auswertung[i]:=0;
max:=strtoint(edit1.text);
if (max>0) then
  begin
  for i:=1 to max do
    begin
    zahl:=random(10);
    auswertung[zahl]:=auswertung[zahl]+1;
    end;
  Anzeige;
  end;
end;

Die AnzeigeProceduer sieht so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Anzeige;//Ergebnisse anzeigen
var i:integer;
begin
for i:=0 to 9 do
  begin
  stringgrid1.cells[1,i+1]:=inttostr(auswertung[i]);
  if not(i>8) then //rel.Hfgk soll nur bei 0..9 erscheinen!
    stringgrid1.cells[2,i+1]:=floattostrF(auswertung[i]/max*100,fffixed,18,2)+'%';
  end;
stringgrid1.cells[1,10]:=edit1.text; //Anzahl
end;


Nun ist bei mir das Problem, dass er zb, wenn ich Anzahl der Durchläufe auf zb. auf 11 setzte, dass er dann mal in der Gesamtzahl der absoluten Häufigkeit 10 Würfe anzeig,t mal 11, dann mal neun usw......
seht ihr einen Fehler in den Procedures?? ich sehen (leider) keinen!
Danke euch!

EDIT: habe mir auch schon i in der Obersten schleife ausgeben lassen, die zählt immer shcön bis max, wie sie es soll....ich verzweifle!
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mo 21.02.05 19:56 
Grad mal so: Hast du im Form1.Create auch randomize; drinne??

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
Kroni Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mo 21.02.05 22:20 
no^^
hab das aber nun gemacht, aber das bringt auch nix!
EDIT: könntet ihr vlt. mal den Code bei euch ausprobieren und testen,ob bei euch bei der eingabe von zb. 11 auch elf in der gesamtzahl der abs. häufigkeiten erscheint??
schlumpf70
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 21



BeitragVerfasst: Mo 21.02.05 22:31 
ähmm entweder blick ichs grad net oder es liegt an der for schleife for 0 to 9
Kroni Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mo 21.02.05 22:49 
es ist ja so, dass er ne zufallszahl zwischen 0 und 9 erzeugt, und dass dann je nachdem im array abspeichert:
ist die zufalls zahl 0 speichert ers in zufall[0] ab und erhöht den zähler dardrin um eins
ist die zufallszahl 1 speichert ers in zufall[1] ab und erhöt dort den zähler um eins usw...
von daher hat das schon seine richtigkeit!
Kokel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 79

XP Prof
delphi 2006 Prof.
BeitragVerfasst: Mo 21.02.05 22:54 
Und wenn es an der var i liegt ?
Okay die variablen sind beide Lokal aber die Prozedure Anzeige hängt das so komisch mit in der schleife. Kann es das sein ?
Kroni Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mo 21.02.05 22:55 
die proz,. anzeige hängt nich tmit in der schleife!
probiert das mal bitte an euern rechner aus....*verzweifel*
EDIT: ICH IDIOT: ich habe die null vergessen bei der ausgabe...ich bin ein idiot, lyncht mich!
sorry
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Di 22.02.05 16:12 
Kroni hat folgendes geschrieben:
no^^
hab das aber nun gemacht, aber das bringt auch nix!

Klar. Deswegen hab ichs ja au net gesagt!! :lol: Probier doch mal deine Funktion aus mit und ohne randomize;!! Dann müsste der erste Wert normal immer derselbe sein! ;) Und das ist wohl seeeehr komisch!!

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.