From d78a70c4733b1009fa8d414b58d82924b342fad3 Mon Sep 17 00:00:00 2001 From: whidix Date: Mon, 2 Mar 2026 12:41:18 +0100 Subject: [PATCH] feat: remove daily character seed from environment and implement random seed generation for selection --- .env.example | 5 ----- src/lib/server/daily-character.ts | 22 +++++----------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/.env.example b/.env.example index 42dc470..ced41bb 100644 --- a/.env.example +++ b/.env.example @@ -7,8 +7,3 @@ ORIGIN="" # For production use 32 characters and generated with high entropy # https://www.better-auth.com/docs/installation BETTER_AUTH_SECRET="" - -# Daily Character Selection -# Seed for daily character selection (default: "onepiecedle") -# Can be any string - will be hashed to generate the rotation -DAILY_CHARACTER_SEED=onepiecedle diff --git a/src/lib/server/daily-character.ts b/src/lib/server/daily-character.ts index 0074488..9149b4b 100644 --- a/src/lib/server/daily-character.ts +++ b/src/lib/server/daily-character.ts @@ -2,21 +2,8 @@ import { db } from '$lib/server/db'; import { arc, character, characterHistory, characterOverride, devilFruit } from '$lib/server/db/schema'; import { desc, eq, inArray, and } from 'drizzle-orm'; -// Get daily character seed from environment or use default -const DAILY_CHARACTER_SEED_STRING = process.env.DAILY_CHARACTER_SEED || 'onepiecedle'; - -// Convert string seed to number using a simple hash function -function hashString(str: string): number { - let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; // Convert to 32bit integer - } - return Math.abs(hash); -} - -const DAILY_CHARACTER_SEED = hashString(DAILY_CHARACTER_SEED_STRING); +// Generate or get random seed for daily character selection +const RANDOM_SEED = Math.random(); const characterWithRelationsSelect = { id: character.id, @@ -168,8 +155,9 @@ export function normalizeDay(date: Date = new Date()): Date { function pickDailyCharacter(characters: CharacterWithRelations[], date: Date): CharacterWithRelations { const timestamp = getDateKey(date); const daysSinceEpoch = Math.floor(timestamp / 1000 / 60 / 60 / 24); - const seed = (daysSinceEpoch + DAILY_CHARACTER_SEED) % characters.length; - return characters[seed]; + // Combine timestamp with random seed to avoid predictable results + const combinedSeed = (daysSinceEpoch + Math.floor(RANDOM_SEED * 1000000)) % characters.length; + return characters[combinedSeed]; } export async function getDailyModeCharacters(): Promise {