From a538710fa1be801c8b4065db8ea8623a720ad18c Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Wed, 4 Jun 2025 22:47:40 +0200 Subject: [PATCH] make pridemonth rng seeded This makes sure the chosen VARIANT for a given day is the same, regardless of whether or not the bot restarts. A different seed it chosen each day and each year of pride month, which should lead to okay results spread wise. --- src/discordbot/events/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/discordbot/events/mod.rs b/src/discordbot/events/mod.rs index 9513d7c..3f32378 100644 --- a/src/discordbot/events/mod.rs +++ b/src/discordbot/events/mod.rs @@ -1,6 +1,6 @@ use chrono::{Datelike, Utc}; use chrono_tz::Europe::Warsaw; -use rand::seq::IndexedRandom; +use rand::{SeedableRng, seq::IndexedRandom}; use serenity::all::{Context, GuildId}; use service::run_event_service; use tracing::info; @@ -86,7 +86,9 @@ impl Event { format!("Gractwo{suffix}") } E::PrideMonth => { - let mut rng = rand::rng(); + let now = Utc::now().with_timezone(&Warsaw); + let seed: u64 = (now.year() as u64) * 1000 + (now.day() as u64); + let mut rng = rand::rngs::SmallRng::seed_from_u64(seed); const VARIANTS: &[&str] = &[ "MiesiÄ…c Dumy", "Pride Month",