From bf09385a34f928e6c266d2f81337237955ee949b Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 25 Sep 2026 20:19:43 +0200 Subject: mass-graduation: keep student selection stable for 45 minutes --- src/mass-graduation.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/mass-graduation.js') diff --git a/src/mass-graduation.js b/src/mass-graduation.js index 335ba16..3bce288 100644 --- a/src/mass-graduation.js +++ b/src/mass-graduation.js @@ -1,7 +1,6 @@ import { GraduationChange, submitGraduationChange } from "./graduation-ENV.ts"; import { fetchStudents } from "./student-ENV.ts"; - -import { getName } from "./utils-ENV.js"; +import { CourseLocalStorage, getName, splitmix32 } from "./utils-ENV.js"; let name; @@ -23,8 +22,19 @@ function toggle(btn, others) { // https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array function shuffleArray(array) { + var seed = JSON.parse(CourseLocalStorage.getItem("bycs-sol-mandatory-seed")); + if (seed === null || Date(seed.endOfLife) < Date()) { + seed = { + seed: (Math.random() * 2 ** 32) >>> 0, + // Keep the same seed for 45 minutes + endOfLife: new Date(new Date().getTime() + 45 * 60000), + }; + CourseLocalStorage.setItem("bycs-sol-mandatory-seed", JSON.stringify(seed)); + } + const rng = splitmix32(seed.seed); + for (let i = array.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); + const j = Math.floor(rng() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; -- cgit v1.2.3