change shuffling function

This commit is contained in:
AlecM33
2022-05-08 22:45:21 -04:00
parent 6ce5cbe59d
commit 0e427de266

View File

@@ -379,7 +379,7 @@ function initializePeopleForGame (uniqueCards, moderator) {
}
}
cards = shuffleArray(cards); // The deck should probably be shuffled, ey?.
cards = shuffle(cards); // The deck should probably be shuffled, ey?.
let j = 0;
if (moderator.userType === globals.USER_TYPES.TEMPORARY_MODERATOR) { // temporary moderators should be dealt in.
@@ -410,13 +410,20 @@ function initializePeopleForGame (uniqueCards, moderator) {
return people;
}
function shuffleArray (array) {
for (let i = 0; i < array.length; i ++) {
const randIndex = Math.floor(Math.random() * i);
const temp = array[i];
array[i] = array[randIndex];
array[randIndex] = temp;
/*
-- To shuffle an array a of n elements (indices 0..n-1):
for i from n1 downto 1 do
j ← random integer such that 0 ≤ j ≤ i
exchange a[j] and a[i]
*/
function shuffle(array) {
for (let i = array.length - 1; i > 0; i --) {
const j = Math.floor(Math.random() * (i + 1));
const temp = array[j];
array[j] = array[i];
array[i] = temp;
}
return array;
}