lundi 18 juillet 2016

How to generate random numbers efficiently using Delphi

i want to generate some random numbers, single,double and triple

i tried this

Procedure TForm1.Button5Click(Sender: TObject);
 var
 c,y,q,N: integer;
 Z ,x,xx,xxx: string;

begin
 Randomize;
 Z := '0123456789';
for c := 1 to 1 do
 begin
  N := Random(Length(Z)) + 1;
  x := x + Z[N];
end;

for y := 1 to 2 do
 begin
  N := Random(Length(Z)) + 1;
  xx := xx + Z[N];
end;

for q := 1 to 3 do
 begin
  N := Random(Length(Z)) + 1;
  xxx := xxx + Z[N];
 end;
 Memo1.Lines.Add(xxx+xx+x+xxx+xx+x+xxx+xx+x);

but i get : 333+22+1+333+22+1+333+22+1 , i want the numbers to be random not the same, i tried also this way, i have repeated IntToStr(RandomRange(0,9) lik 900 times and i got an erroe

Memo1.Lines.Add(IntToStr(RandomRange(0,9))+','+IntToStr(RandomRange(11, 99))+ IntToStr(RandomRange(101, 999))); 

but i get an error in Delphi 10 which says that the text is too long and was turcated, b need help guys please, Thanks




Aucun commentaire:

Enregistrer un commentaire