RandomizeList

List command

Syntax

Shuffles the elements of a list, or of a range of it, into a random order.

RandomizeList(<list>() [, <start>, <end>])

Parts

<list>A list declared with NewList, written with its empty parentheses: scores().
<start>Optional. The position of the first element to shuffle, from 0.
<end>Optional, required with <start>. The position of the last element to shuffle, included.

Good to know

  • Returns nothing: write it on its own line.
  • After the shuffle there is no current element.
  • Without <start> and <end>, the whole list is used. Giving only <start> compiles but stops the program with "BASIC collection range requires start and end". A range outside the list stops it with "BASIC collection range is out of bounds".
  • After FreeList(), the call stops the program with "BASIC list is not initialized".

Example

NewList a.integer()FOR k = 1 TO 5  AddElement(a())  a() = kNEXTRandomizeList(a())total = 0FOREACH a()  total = total + a()NEXTConsole(Str(ListSize(a())) + " " + Str(total))   ' 5 15, same values in a new order
In the manual : Arrays, lists and maps