Skip to main content

draw

Draw a random item from a list. Returns null if the list is empty.

This helper can also be useful for using inside tests where - given a list of possible outcomes - one is randomly selected.

API

function random(lower?: number, upper?: number | boolean, floating?: boolean): number;

Usage

import { draw } from '@feedzai/js-utilities';

const SIMPSONS = [
"Homer Simpson",
"Marge Simpson",
"Bart Simpson",
"Lisa Simpson",
"Maggie Simpson",
];

draw(SIMPSONS)
// => a random Simpsons Character e.g "Bart Simpson"