Method
Arrays.Shuffle
Description
Shuffles (rearranges randomly) the elements of an array.
Usage
array.Shuffle
Part |
Type |
Description |
---|---|---|
array |
Any valid data type |
The array whose elements will be shuffled. |
Notes
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)
values.Shuffle
Var result As String
For Each item As Integer In values
result = result + item.ToString
Next
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
Next
Next
myArray.Shuffle
Compatibility
All project types on all supported operating systems.
See also
Arrays parent class; Var statement; Arrays concept for a complete list of functions; ParamArray keyword