A mutating (in-place) uniformly random array shuffle.
Time complexity: O(n)
Space complexity: O(1)
Array to shuffle
Optional
Optional, true if specified
true
const array = [1, 2, 3];shuffle(array); Copy
const array = [1, 2, 3];shuffle(array);
sample if you only want to select one element at random
Array
A non-mutating uniformly random array shuffle.
Space complexity: O(n)
false
The shuffled array
const array = [1, 2, 3];const shuffled = shuffle(array, false); Copy
const array = [1, 2, 3];const shuffled = shuffle(array, false);
A mutating (in-place) uniformly random array shuffle.
Time complexity: O(n)
Space complexity: O(1)