ferroid 2.0.0

High-performance ULID and Snowflake-style IDs. Unique, monotonic, and lexicographically sortable IDs optimized for low-latency services and async workloads.
Documentation
use rand::{RngExt, rng};

use crate::rand::RandSource;

/// A `RandSource` that uses the thread-local RNG (`rand::rng()`).
///
/// This RNG is fast, cryptographically secure (ChaCha-based), and automatically
/// reseeded periodically.
///
/// Each OS thread has its own RNG instance, so calls from multiple threads are
/// contention-free and safe. This type does **not** store the RNG itself; it
/// simply accesses the thread-local generator on each call.
#[derive(Default, Clone, Debug)]
pub struct ThreadRandom;

impl RandSource<u64> for ThreadRandom {
    fn rand(&self) -> u64 {
        rng().random()
    }
}

impl RandSource<u128> for ThreadRandom {
    fn rand(&self) -> u128 {
        rng().random()
    }
}