Files
rummikid/modules/lib/random.js

25 lines
485 B
JavaScript

export const shuffle = (array, seed) => {
const randomArray = [...array];
let m = array.length;
let t;
let i;
while (m) {
// Pick a remaining element…
i = Math.floor(random(seed) * m--);
// And swap it with the current element.
t = randomArray[m];
randomArray[m] = randomArray[i];
randomArray[i] = t;
++seed;
}
return randomArray;
};
export const random = (seed) => {
const x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
};