Re: TIB:random


[Prev][Next][Index][Thread]

Re: TIB:random




Nathan Gaylinn wrote:
> 
> I think we talked about this way back when, but can anyone help me
> figure out how to get a random # 1-25 without repeats on an 82?
> I don't actually have an 82, this is for a friend of mine, so I can't
> check things right away.

Create a list with the numbers 1, 2, 3, ..., 25. (Use seq() - it's
the easiest way.)

Then you must "shuffle" this list. Pseudocode:

For i=1 to 25
  a=random number 1..25
  swap contents of list(a) and list(i)
Next i

You can repeat this loop as many times as you want, but once should
be enough.

Now, simply pick one number at a time from the list (starting with
the first, of course, then the second and so on) and there you
have random numbers 1..25 without repeats since each number exists
only once in the list!

//Johan


References: