Link to home
Start Free TrialLog in
Avatar of dluedi
dluedi

asked on

Random!!!

Hello everybody
Actually I just need a procedure that runs randomly  one of the
case...of numbers (look below), but thats not all, the difficult part is that it has to run all numbers, and not a number twice. I hope you understood.

Here an example, the first number is randomly selected between 1 and
10 e.x: 9 now it runs in the case...of:
9: begin {do something} end;  
ok the whole procedure runs totally 10 times, so the next time maybe 2 is selected but not 9! I tried to show the procedure how it should look like:


procedure rand;
var

what:integer;
{your vars}

begin

randomize;
{your code}

case what of

1:     begin
     {do my code}
     end;
2:     begin
     {do my code}
     end;
3:     begin
     {do my code}
     end;
{...}
{the numbers go until 10, each number only once!}
end;

end;

{By the way I tried to make it simple, because in my application it has
to choose from about 70 (!) numbers. I wrote my own code, but it didn't work; because it's quite long I didn't post it.}

:)dluedi
ASKER CERTIFIED SOLUTION
Avatar of DidierD
DidierD
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dyancer
dyancer

try this url,
I hope it help you.
http://www.delphi3000.com/articles/article_1898.asp

Hi,

I am not sure but I think you are looking for something like this:


procedure TfrmMain.Button1Click(Sender: TObject);
var i, j : integer; numbers : string;
begin

  randomize;
  numbers := '';
  for j := 0 to 8 do
    while true do begin
      //this gives random numbers between 1 and 10
      i := Random(10 - (1 + 1)) + 1 + 1 ;
      if pos(IntToStr(i),numbers) = 0 then begin
        numbers := numbers + IntToStr(i);
        showmessage(IntToStr(i));
        break;
      end;
    end
end;

Good luck

Marcel    
Avatar of dluedi

ASKER

Actually this was already the answer to my question, that went farst! Thx to everybody else who tried to help!