Function Reference


_ArrayShuffle

Shuffles selected rows of 1D or 2D arrays - can be limited to a specific column in 2D arrays

#include <Array.au3>
_ArrayShuffle ( ByRef $aArray [, $iStart_Row = 0 [, $iEnd_Row = 0 [, $iCol = -1]]] )

Parameters

$aArray Array to modify
$iStart_Row [optional] Start row for shuffle - default first
$iEnd_Row [optional] End row for shuffle - default last
$iCol [optional] Specific column to shuffle (2D only)

Return Value

Success: 1.
Failure: -1 and sets the @error flag to non-zero.
@error: 1 - $aArray is not an array
2 - $aArray is not a 1D or 2D array
3 - $iStart or $iEnd outside array bounds
4 - $iStart greater than $iEnd
5 - $iColumn is outside array bounds

Remarks

The function uses the Fisher-Yates shuffle algorithm.

Example

#include <Array.au3>

Local $aArray_Base[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_ArrayDisplay($aArray_Base, "1D - Original", Default, 8)

Local $aArray = $aArray_Base
_ArrayShuffle($aArray)
_ArrayDisplay($aArray, "1D - Shuffled", Default, 8)

$aArray = $aArray_Base
_ArrayShuffle($aArray, 3, 8)
_ArrayDisplay($aArray, "1D - Shuffled - 3-8 ", Default, 8)

Local $aArray_Base[10][10]
For $i = 0 To 9
        For $j = 0 To 9
                $aArray_Base[$i][$j] = $i
        Next
Next
_ArrayDisplay($aArray_Base, "2D - Original", Default, 8)

$aArray = $aArray_Base
_ArrayShuffle($aArray)
_ArrayDisplay($aArray, "2D - Shuffled - All rows", Default, 8)

$aArray = $aArray_Base
_ArrayShuffle($aArray, 3, 8, 2)
_ArrayDisplay($aArray, "2D - Shuffled - Col 2, 3-8", Default, 8)