Pick Random
Pick a specified number of random items from an array without repeating.
| Category | Random |
| Author | Polgubau |
| Since | 1.0.4 |
| Last Updated | 2025-03-17 |
| Type | Sync |
| Compatibility | Universal |
Example
Input
pickRandom([1, 2, 3, 4, 5], 3)Output:
[2, 4, 5] // (random items, could be any combination from the array)
Input
pickRandom(['apple', 'banana', 'cherry', 'date'], 2)Output:
["banana", "cherry"] // (random items, could be any combination from the array)
Return
An array containing the randomly selected items.
Type: T[]
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| array | T[] | null | No | The input array to pick random items from. |
| count | number | null | No | The number of random items to pick. |
Notes
This function returns an empty array if the count is less than or equal to zero, or if the input array is empty.
Tags
- random
- array
- utilities