Building a Non-repeating list


[ Zettels Traum ] [ search / suche ]

von dp am 28.Juli 97 um 00:39:05:

Okay, gather 'round everyone! This handler makes a list of numbers in
random order.

on makeRandomList passedNumber
  global gRandomList
  set gRandomList to []
  repeat with x = 1 to passedNumber
    addAt(gRandomList, Random(x), x)
  end repeat
end makeRandomList

Clean and simple. Then all you need call is:

makeRandomList 5

and you'll get something like this:

[3, 1, 4, 2, 5]

The secret is that you repeat with the known numbers (1 - 5), and what
you randomize is the placement of those numbers within the list. Enjoy!


George Langley



Dazu:























D. Plänitz