Autor Beitrag
bluecat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 24.04.05 13:59 
Hallo leute!

wie kann ich eine array den wert zufällig generieren? kann jemand mir helfen
Danke im voraus

Moderiert von user profile iconTino: Titel geändert.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 24.04.05 13:59 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(5001)
 end;
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: So 24.04.05 14:01 
Rufe aber randomize vorher auf, sonnst kommt bei mehrmaligen Zuweiungen immmer die gleichw Zahl
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 24.04.05 14:07 
Das setzte ich als schon bekannt voraus :wink: .
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: So 24.04.05 14:11 
ich finde es grundsätzlich besser, wenn die dazugehörigen Themen in einen Thread gleich mit reingepackt werden. Sonnst muss man immer noch ewig einzelne Befehle zusammensuchen, befor man auf nen grünen Zweig kommt!
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: So 24.04.05 14:40 
Heiko wie kannste das denn vorrausetzen wenn der threadsteller nicht mal random kennt?

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 24.04.05 16:02 
Ich habe seine Frage so aufgefasst, dass er Random kennt, aber nicht weiß, wie er das in arrays einspeichert :wink: .
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: So 24.04.05 16:54 
Schön zu wissen, denn ich setz als bekannt voraus, dass Themen zum Zufall bereits zu Hauf behandelt wurden. Ein Verweis auf die Suchfunktion hätte zufälligerweise auch geholfen... :twisted:

_________________
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.
bluecat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 24.04.05 16:58 
Titel: Random
user profile iconHeiko hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(5001)
 end;


danke erstmal an aller, die meine Frage beanworteten!
gibt es die Mglkt, dass die Zufall sowohl negativ als auch negaviv sein kann?
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: So 24.04.05 17:00 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(2501)-random(5001);
 end;
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: So 24.04.05 17:13 
user profile iconWeBsPaCe hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(2501)-random(5001);
 end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=2500-random(5001);
 end;


Ist intuitiver und der Bereich ist auch offensichtlicher ...

_________________
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.
bluecat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 24.04.05 17:13 
user profile iconWeBsPaCe hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(2501)-random(5001);
 end;


Kann man auch in einem offenen Bereich ( type Extended) definieren?
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: So 24.04.05 17:15 
user profile iconBenBE hat folgendes geschrieben:
Ist intuitiver und der Bereich ist auch offensichtlicher ...

Oooops. Natürlich. Sollte auch so heißten. Sorry. ;)
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 24.04.05 17:19 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=(2500-random(5000)) / (random(2499)+1);
 end;

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
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: So 24.04.05 17:23 
Auch wieder intuitiver wäre:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=2500 - 5000 * random;
 end;

_________________
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.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 24.04.05 20:12 
user profile iconWeBsPaCe hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=0 to High(arrayName) do
 begin
  arrayName[i]:=random(2501)-random(5001);
 end;

Hier ist nicht nur der Bereich weniger offensichtlich, sondern die Zahlen sind auch nicht gleichverteilt! Die Zahlen sind bloss zwischen [-2500..0] gleichverteilt - im Bereich [-5000..-2501] und [1..2500] nimmt die Wahrscheinlichkeit linear bis 0 ab, dort ist die Wahrscheinlichkeit also jeweils tiefer!
Die Lösung von user profile iconBenBe ist korrekt. :) (Man sollte sich aber bewusst sein, dass die Zahl 2500 gezogen werden kann, jedoch -2500 nicht mehr)
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: Mo 25.04.05 08:40 
user profile icondelfiphan hat folgendes geschrieben:
Hier ist nicht nur der Bereich weniger offensichtlich, sondern die Zahlen sind auch nicht gleichverteilt! Die Zahlen sind bloss zwischen [-2500..0] gleichverteilt - im Bereich [-5000..-2501] und [1..2500] nimmt die Wahrscheinlichkeit linear bis 0 ab, dort ist die Wahrscheinlichkeit also jeweils tiefer!

Bei user profile iconWeBsPaCe sollte man sich sogar noch bewusst sein, dass seine Variante nur Integer-Werte zurückgibt, da Random bei Angabe einer Zahl IMMER auf Integer rundet.

user profile icondelfiphan hat folgendes geschrieben:
Die Lösung von user profile iconBenBe ist korrekt. :) (Man sollte sich aber bewusst sein, dass die Zahl 2500 gezogen werden kann, jedoch -2500 nicht mehr)
Kleinigkeit: Bitte das letzte E im Nick groß schreiben ... Bei user profile iconWeBsPaCe klappt die korrekte Schreibweise doch auch :lol:

_________________
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.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 25.04.05 11:34 
[OT]@BenBE: Gut ja, das mit dem Float, das kam ja dann später, aber okay. Und wegen deinem Namen; ich werd mir in Zukunft mehr Mühe geben ;)[/OT]
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 11:52 
Okay zu dem Thema hab ich noch 2 Fragen und zwar will ich mir mit dem Befehl random eine kommazahl ausgeben lassen klappt bei mir nicht kommt nur eine schwule ganzzahl und ich möchte zwischen einen Bereich mir Zahlen geben lassen also praktisch zwischen 10 und 15 soll er mir eine Zahl raussuchen!

THX im Vorhinein

Beutel
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: Mo 22.08.05 12:06 
glaub das musste dir selbs schreiben -> einfach 2 ganzzahlen generieren lassen und die 2. also nachkommastelle benutzen

var bla: real;
begin
bla := random(100)+random(100000) / 1000000;
edn;

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