blob: 68511d487ef2fbaf03a6f9d3d68a9c4d641c1351 [file] [log] [blame] [view]
---
{
"title": "ARRAY_SHUFFLE",
"language": "en-US",
"description": "Randomly shuffle the order of elements in an array."
}
---
## Function
Randomly shuffle the order of elements in an array.
## Syntax
- `ARRAY_SHUFFLE(arr)`
- `ARRAY_SHUFFLE(arr, seed)`
## Parameters
- `arr`: `ARRAY<T>`.
- `seed`: optional, random seed.
## Return value
- Returns an array of the same type as the input, with elements randomly reordered. Element count and types remain unchanged.
## Usage notes
- If the input `arr` is `NULL`, returns `NULL`.
- Providing a `seed` yields reproducible results; omitting it may yield different results per execution.
- `ARRAY_SHUFFLE` has an alias `SHUFFLE`; they are equivalent.
-
## Examples
- Basic usage:
- `ARRAY_SHUFFLE([1, 2, 3, 4])` -> e.g. `[3, 1, 4, 2]` (random order)
- `ARRAY_SHUFFLE(['a', null, 'b'])` -> e.g. `['b', 'a', null]`
- With a fixed seed (reproducible results):
- `ARRAY_SHUFFLE([1, 2, 3, 4], 0)` -> same order each time (e.g. `[1, 3, 2, 4]`)