Skip to content

shuffle

shuffle(x, randomSource?): any[]

Defined in: src/shuffle.js:17

A Fisher-Yates shuffle is a fast way to create a random permutation of a finite set. This is a function around shuffle_in_place that adds the guarantee that it will not modify its input.

any[]

sample of 0 or more numbers

Function

an optional entropy source that returns numbers between 0 inclusive and 1 exclusive: the range [0, 1)

any[]

shuffled version of input

var shuffled = shuffle([1, 2, 3, 4]);
shuffled; // = [2, 3, 1, 4] or any other random permutation