Skip to content

Commit 741c7bb

Browse files
committed
Changed name randomization to weighted randomization
1 parent 457f263 commit 741c7bb

File tree

1 file changed

+8
-7
lines changed
  • viewer-queue-webserver/src/utils

1 file changed

+8
-7
lines changed

viewer-queue-webserver/src/utils/names.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { db } from "./db.js";
22
import { io } from "../webserver.js";
3+
import { getWeightedRandomIndex } from "./miscutils.js";
34
console.log("Running db query");
45
const doc = process.env.DEV ? "namesListsDev" : "namesLists";
56
const docRef = db.collection("ViewerQueue").doc(doc);
@@ -13,7 +14,11 @@ export let nameGraveyard: { [key: string]: boolean } = document?.data()?.nameGra
1314
export async function addName(name: string) {
1415
if (name === "testSet") {
1516
//TODO: remove this later
16-
const testNames = ["test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10"];
17+
18+
const testNames = new Array<string>();
19+
for (let i = 1; i <= 10; i++) {
20+
testNames.push(`test${i}`);
21+
}
1722
queuedNames = testNames;
1823
await docRef.update({ queuedNames });
1924
io.emit("refresh-lists", queuedNames, poppedNames, nameGraveyard);
@@ -84,13 +89,9 @@ export async function popName(random: boolean) {
8489
poppedNames.unshift(name);
8590
} else {
8691
let idx: number = -1;
87-
// if (queuedNames.includes("eyemozzie")) {
88-
// name = "eyemozzie";
89-
// idx = queuedNames.findIndex((s) => s === name);
90-
// } else {
91-
idx = Math.floor(Math.random() * queuedNames.length);
92+
// idx = Math.floor(Math.random() * queuedNames.length);
93+
idx = getWeightedRandomIndex(queuedNames);
9294
name = queuedNames[idx];
93-
// }
9495
queuedNames.splice(idx, 1);
9596
poppedNames.unshift(name);
9697
}

0 commit comments

Comments
 (0)