UNPKG

deep-random-pick

Version:

Picks a pseudo-random item from a pool in several ways, including a recursive method that allows for more control over probability.

12 lines (10 loc) 330 B
import { shallowPick } from './shallowpick'; export const randomPick = (...items) => { const itemPicked = shallowPick(items); if (Array.isArray(itemPicked) && itemPicked.length > 0) { // Recursion is required here. return randomPick(itemPicked); } else { return itemPicked; } }