@polkadot/util
Version:
A collection of useful utilities for @polkadot
18 lines (15 loc) • 417 B
JavaScript
// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export function arrayShuffle(input) {
const result = input.slice();
let curr = result.length;
if (curr === 1) {
return result;
}
while (curr !== 0) {
const rand = Math.floor(Math.random() * curr);
curr--;
[result[curr], result[rand]] = [result[rand], result[curr]];
}
return result;
}