Returns a random value from array
,
and removes it from the array.
const data = [100,20,50];
const v = randomPluck(data, { mutate: true });
// eg: v: 20, data is now [100,50]
Returns a random element from an array along with the remaining elements. Does not modify the original array.
const data = [100,20,50];
const {value,remainder} = randomPluck(data);
// eg: value: 20, remainder: [100,50], data remains [100,20,50]
Optional
options: { mutate: false; source?: RandomSource }
Plucks a random value from an array, optionally mutating the original array.
Example: Get a random element without modifying array
Example: Get a random element, removing it from original array
If the input array is empty, undefined is returned as the value.
Type Param: V
Type of items in array
Param: array
Array to pluck item from
Param: options
Options. By default { mutate: false, source: Math.random }
Param: rand
Random generator.
Math.random
by default.