From Xojo Documentation

Revision as of 22:32, 29 July 2019 by Gperlman (talk | contribs)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Shuffles (rearranges randomly) the elements of an array.



Part Type Description
array Any valid data type The array whose elements will be shuffled.


Shuffle works on arrays of any data type and any number of dimensions. It is based on a random number. An element of the original array has a roughly equal chance of appearing in any cell of the array after the shuffle, regardless of the size and number of dimensions of the array.

A Fisher-Yates shuffle is used. There is no ability to control the seed.

Sample Code

Shuffle a one-dimensional array:

Var values() As Integer = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Var result As String
For i As Integer = 0 To values.LastRowIndex
result = result + i.ToString

Shuffle a two-dimensional array:

Var myArray(5, 5) As Text
For i As Integer = 0 To 5
For j As Integer = 0 To 5
myArray(i, j) = i.ToString + j.ToString

See Also

Var statement; Arrays concept for a complete list of functions; ParamArray keyword