Autor Beitrag
darkdester
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 20.10.04 11:23 
Hallo^^

ich hab mal wieder seit langem ne frage und zwar hab ich hier en var-array
wie tu ich jetzt das mit der random-funktion benutzen?
ausblenden Delphi-Quelltext
1:
2:
randomize;
Edit10.Text:=random(test[1], test[2])



also so funzt es net

da gibts probs mit typ array und integer
nur meine vars sind vom Typ String


kann mir please jemand helfen?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 20.10.04 11:26 
Random hat nur einen Parameter. Ausführliche Infos gibts in der OH. Außerdem ist der Rückgabewert eine Zahl. Die kannst einem String so nicht zuweisen.
EDIT: Wo ist denn da ein Array?
jojo-sp
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

Windows XP Prof, Vista Ultimate & Home Premium, Windows 7
Delphi 7 Enterprise, Delphi 2009
BeitragVerfasst: Mi 20.10.04 11:35 
Wenn ich dich richtig verstehe, dann musst du erst das array füllen.
Es kommt natürlich auch wieder darauf an, ob du ein Array mit fester oder Variabler länge haben willst.

z.B.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure ....;
Var
    VarArray : array[0..99of integer; // Array mit der Länge 100
    loop:integer;
Begin
  randomize;
  For loop:=low(VarArray) to high(VarArray) Do
  Begin
    VarArray[loop]:=random(100); //In VarArray wird ein Wert zwischen -1 & 101 eingetragen
  End;
End;


Das random funktioniert nur bei Integerwerten.

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
darkdester Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 20.10.04 15:33 
random nur bei integer werte O.O

na toll meine var array beinhaltet aba auch buchstaben net nur zahlen
habs als string deshalb genomme

ich will aber das der das zufaäälig ausgibt ins edit3.text oda so halt
also eine der vars aus dem array
jojo-sp
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

Windows XP Prof, Vista Ultimate & Home Premium, Windows 7
Delphi 7 Enterprise, Delphi 2009
BeitragVerfasst: Mi 20.10.04 15:44 
Drück dich mal lieber etwas genauer aus.

Eigentlcih solltest du es selber machen, aber ich hab heute meinen sozialen Tag,
wenn du zufällig einen Wert das arrays haben willst, musst du es so machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure ...
var
    myarray : array[0..99of string;
    i : integer;
begin
  randomize;
  i := random(length(myarray)-1); // Spuckt eine Zahlenwert zwischen 0 und 99 aus
                                  // besonders wichtig, wenn das Array dynamisch ist,  
                                  // hier würde aber auch einfach die Zahl 99 reichen
  edit1.text := myarray[i];
end;


Wenn du es jetzt noch nicht peilst, kann ich dir nit mehr helfen.

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

_________________
Ist der Ruf erst ruiniert, lebts sich gänzlich ungeniert...
Wilhelm Busch (1832 - 1908)
darkdester Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 20.10.04 17:52 
DANKE
darkdester Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 20.10.04 17:59 
ehm prob es funzt zwar aba manchmal gibt er '$£B' aus Oo

obowhl das nicht drin ist

was bedeuted das -1? (random(length(test)-1);
Maweki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 197

Ubuntu Linux
Lazarus
BeitragVerfasst: Mi 20.10.04 18:03 
hier nur mal so die Delphi-Hilfe zum Thema:
Zitat:
function Random [ ( Range: Integer) ];

Description

Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range

0 <= X < 1.

To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.