iocaine 1.0.0

The deadliest poison known to AI
Documentation
// SPDX-FileCopyrightText: 2025 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: MIT

use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use sha2::{Digest, Sha256};

pub struct GobbledyGook;

impl GobbledyGook {
    pub fn for_url<S: AsRef<str>>(seed: S) -> ChaCha20Rng {
        let mut hasher = Sha256::new();
        hasher.update(seed.as_ref().as_bytes());
        let seed = hasher.finalize().into_iter().fold(0, |acc: u64, v| {
            acc.wrapping_mul(256).wrapping_add(v as u64)
        });

        ChaCha20Rng::seed_from_u64(seed)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use rand::Rng;

    #[test]
    fn test_stable_rng() {
        let mut rng_test1 = GobbledyGook::for_url("/test");
        let mut rng_test2 = GobbledyGook::for_url("/test");
        let mut rng_other = GobbledyGook::for_url("/other");

        let t1: u8 = rng_test1.random();
        let t2: u8 = rng_test2.random();
        let t3: u8 = rng_other.random();

        assert_eq!(t1, t2);
        assert_ne!(t2, t3);
    }
}