UNPKG

@technobuddha/library

Version:
13 lines (12 loc) 377 B
/** * Pick a random items from a list. * * @param list Array of items to pick from * @param random Random number generator * @default random Math.random * @returns Randomly selected item */ export function randomPick(list, random = Math.random) { return list.length === 0 ? undefined : list[Math.floor(random() * list.length)]; } export default randomPick;