src/util/Util.js
/**
 * Pick a random value from an array, uses `util.shuffle` to shuffle the array and returns the last value.
 *
 * @name module:util.randchoice
 * @function
 * @public
 * @param {Object[]} array - the input 1-D array
 * @param {Function} [randomNumberGenerator = undefined] - A function used to generated random numbers in the interal [0, 1). Defaults to Math.random
 * @return {Object[]} a chosen value from the array
 */
Pick a random value from an array, uses `util.shuffle` to shuffle the array and returns the last value.
Pick a random value from an array uses ` util . shuffle ` to shuffle the array and returns the last value .
function randchoice(array, randomNumberGenerator = undefined)
{
	if (randomNumberGenerator === undefined)
	{
		randomNumberGenerator = Math.random;
	}
	const j = Math.floor(randomNumberGenerator() * array.length);
	return array[j]
}
function randchoice ( array , randomNumberGenerator = undefined ) { if ( randomNumberGenerator === undefined ) { randomNumberGenerator = Math . random ; } const j = Math . floor ( randomNumberGenerator ( ) * array . length ) ; return array [ j ] }
Pick a random value from an array, uses `util.shuffle` to shuffle the array and returns the last value.
Pick a random value from an array uses ` util . shuffle ` to shuffle the array and returns the last value .