Skip to content
Snippets Groups Projects
Commit e52551ee authored by Quentin Bramas's avatar Quentin Bramas
Browse files

forgot to add a file

parent cdffbebe
Branches
Tags v0.5
No related merge requests found
Pipeline #340666 passed with warnings with stages
in 2 minutes and 29 seconds
// from https://github.com/bryc/code/blob/master/jshash/PRNGs.md#mulberry32
function mulberry32(a) {
return function () {
a |= 0; a = a + 0x6D2B79F5 | 0;
var t = Math.imul(a ^ a >>> 15, 1 | a);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
}
// Fisher–Yates Shuffle
export default function shuffle(array, seed) {
array = [...array];
let getRand = mulberry32(seed);
let currentIndex = array.length;
while (currentIndex != 0) {
let randomIndex = Math.floor(getRand() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]
];
}
return array;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment