From 7394a1c94ce16aa3b4c3a2ff9b95e7f1aed72fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CA=9C=C9=AA=C9=B4=E1=B4=87=C9=AA=20N=E1=B4=8F=E1=B4=9C?= =?UTF-8?q?=E1=B4=A2=E1=B4=87=C9=B4?= <157171073+Shineii86@users.noreply.github.com> Date: Thu, 25 Jun 2026 10:00:28 +0530 Subject: [PATCH] Improve random entropy with multi-source seed --- src/routes/apiRoutes.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routes/apiRoutes.js b/src/routes/apiRoutes.js index 5c4ebaf..325a3a3 100644 --- a/src/routes/apiRoutes.js +++ b/src/routes/apiRoutes.js @@ -320,10 +320,11 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => { // ---- FEATURE: Random anime of the day ---- router.get("/random", async (req, res) => { try { - // NOTE: Use Date.now() + process.hrtime for randomness in serverless + // NOTE: Use multiple entropy sources for randomness in serverless + const now = Date.now(); const hrtime = process.hrtime(); - const seed = Date.now() ^ (hrtime[0] * 1000 + hrtime[1]); - const randomPage = (Math.abs(seed) % 499) + 1; + const entropy = (now * 31 + hrtime[0] * 17 + hrtime[1] * 13) ^ (process.pid * 7); + const randomPage = (Math.abs(entropy) % 499) + 1; const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1); const anime = data.results[0];