Autor Beitrag
LoI
Hält's aus hier
Beiträge: 5

Win 2000
D6 Pers
BeitragVerfasst: Sa 27.08.05 19:53 
Hallo!

Ich beschäftige mich erst seit kuirzem mit Delphi und bin noch nicht wirklich hinter das Geheimnis gekommen... deshalb meine Frage:

Wie kann ich es anstellen, dass der Zufallsgenerator nur eine bestimmte Anzahl von Zufallszahlen erzeugt und anzeigt?

Danke, LoI
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 27.08.05 19:55 
randomize // zufallsgen initialisieren

random(20) zahlen von 0-19

hättest aber auch alles denk ich mal durch die suche gefunden

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
LoI Threadstarter
Hält's aus hier
Beiträge: 5

Win 2000
D6 Pers
BeitragVerfasst: Sa 27.08.05 19:57 
Nein, das meine ich nicht. In welchem Raum die Zufallszahlen generiert werden sollen, habe ich. Aber die Anzahl der angezeigten Zahlen will ich bestimmen. Die sollen nicht zwischen 1 und 20 liegen, sondern sollen eben nur bspw. 3 betragen.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 27.08.05 20:08 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
i:Integer;
Edit1.Text:=StrToInt(i)
Random(i)
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Sa 27.08.05 20:11 
ka ob ichs richtig verstehe, aba du willst z.B. das der 3 Zufallszahlen oder 7 ermittelt?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure zufall;
var i:integer;
    zahl:real;
begin
randomize;
for i:=0 to <anzahl> do
begin
zahl:=random(20)+1;
listbox1.items.add(inttostr(zahl));
end;
end;

_________________
GEIZ IST GEIL! - Ihr Sozialamt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 27.08.05 20:18 
Meinst du sowas?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Button1Click(Sender: TObject);
var arr: array[0..30of integer;
  i,z:integer;
begin
  randomize;
  // Array initialisieren
  for i:=0 to 30 do
    arr[i] := 0;

  // 100 mal eine Zufallszahl erzeugen und
  // das Array an der entsprechenden Stelle erhöhen
  for i:=1 to 100 do
  begin
    z := random(31);
    arr[z] := arr[z]+1;
  end;

  // Ausgabe
  for i:=0 to 30 do
    memo1.Lines.add(inttostr(i) + ': ' + inttostr(arr[i]));
end;

_________________
We are, we were and will not be.
LoI Threadstarter
Hält's aus hier
Beiträge: 5

Win 2000
D6 Pers
BeitragVerfasst: Sa 27.08.05 20:20 
Danke für die Antworten, aber irgendwie kriege ich das nicht hin.

Also ungefähr so: Per Zufallsgenerator sollen Zahlen in eine Tabelle gesetzt werden. Die Zahlenwahl soll zufällig sein. Aber die Anzahl der Zahlen, die dort reingesetzt wird beträgt halt nur bspw. 3.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 27.08.05 20:23 
dann rufst du 3 mal random auf


wenn du aber willst das 3 zufallszahlen von 0..2 erstellt werden sollen und jede nur EINMAL dann musst du dich selbst drum kümmern, aber deine formulierungen sind echt nich zu verstehen ;P

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 27.08.05 20:28 
Sowie sich das anhöhrt 6 aus 49 ?
LoI Threadstarter
Hält's aus hier
Beiträge: 5

Win 2000
D6 Pers
BeitragVerfasst: Sa 27.08.05 20:38 
Ja, 6 aus 49. Ein Lottogenerator - nicht einmal sowas Einfaches bekomme ich hin.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 27.08.05 20:41 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var i : integer;
bla: array[1..49of boolean;
begin
  for i := low(bla) to high(bla) do bla[i] := false;
  for i := 1 to 6 do
  begin
    repeat 
     j := random(49)+1
    until bla[j] = false;
    bla[j] := true;
    listbox1.items.add(inttostr(j));
  end;
end;

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
LoI Threadstarter
Hält's aus hier
Beiträge: 5

Win 2000
D6 Pers
BeitragVerfasst: Sa 27.08.05 20:50 
Ich arbeite mit StringGrid... daher funktioniert das mit der Listbox nicht. Und wenn ich den Namen einfach austausche, dann geht es trotzdem nicht.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 27.08.05 20:53 

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit