🧩 Returns a random element from the given array using cryptographically strong randomness.
Syntax
TypeScript
import { sample } from '@opentf/std'; sample<T>(arr: T[] = []): T | undefined
Parameters
arr: The source array.
Returns
A random element, or undefined if the array is empty.
Examples
TypeScript
sample([1, 2, 3]) //=> 1, 2, or 3 (random) sample([]) //=> undefined