Ok this is the code I am using with...
following variables ...
//i,idx are Integer
//Amount is an array and I want to sort it after inserting value with random function....
Now the problem I am facing is that everytime I run this the random function always generate the same random numbers...
Why is it so and what can I do to generate new random numbers everytime I run this code.
//This is the Coding is some one want to refer..
FOR i := 1 TO 10 DO BEGIN
amount := RANDOM(temp);
MESSAGE('Value of Amount(%1) = %2',i,amount);
END;
MESSAGE('Length of array=(%1)',ARRAYLEN(amount));
FOR i:= 1 TO 10 DO BEGIN
FOR idx := ARRAYLEN(amount) DOWNTO 2 DO
IF amount[idx] < amount[idx-1] THEN BEGIN
TempAmount := amount[idx];
amount[idx] := amount[idx-1];
amount[idx-1] := TempAmount;
END;
END;
FOR i := 1 TO 10 DO BEGIN
MESSAGE('Value of Amount(%1) = %2',i,amount);
END;
Rule from today: Never take others comment in a wrong way, these might help you to travel a long way in your carrier.
0
Answers
If you need a really random number, u can also use a guid and eleminate there the chars like A..Z and {}
Randomize;
amount := RANDOM(temp);
@ Suvidha..
Now the problem I am facing is that even though random is now generating different value each time I run the code but every element of the amount array have the same value..
Please have a look at it..
maybee copy the code into a codeunit and try running it.
My Blog - nav.education
temp :=100;
I did initialized but forgot to mention it..
RANDOMIZE;
FOR i := 1 TO 10 DO BEGIN
amount := RANDOM(temp);
//MESSAGE('Value of Amount(%1) = %2',i,amount);
END;
That code generates different numbers every time I run it on my machine. Is that the same code that you have?
My Blog - nav.education
Randomize(i);
Yes it is working perfectly now...
Thanks a lot...