Skip to content

random

ts
function Array.random<T>(target: readonly T[]): T | undefined

Returns a random element from array, or undefined if the array is empty.

Example

ts
import { Array } from "@monstermann/array";

Array.random([1, 2, 3, 4]); // 2 (random)
ts
import { Array } from "@monstermann/array";

pipe([1, 2, 3, 4], Array.random()); // 2 (random)