Method

# Arrays.Shuffle

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Shuffles (rearranges randomly) the elements of an array.

## Usage

``` xojo
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 <span class="title-ref">Shuffle</span>, regardless of the size and number of dimensions of the array.

A [Fisher-Yates](http://en.wikipedia.org/wiki/Fisher–Yates_Shuffle) <span class="title-ref">Shuffle</span> is used. There is no ability to control the seed.

## Sample code

Shuffle a one-dimensional array:

``` xojo
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:

``` xojo
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

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Arrays</api/language/arrays>` parent class; `Var</api/language/var>` statement; `Arrays</api/language/arrays>` concept for a complete list of functions; `ParamArray</api/language/paramarray>` keyword

</div>
