Documentation
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(unix)]
pub mod unix;
pub mod mt19937;
pub mod dist;
mod impls;

/// A source of randomness
pub trait RandomSource {
    /// Fills the given buffer of bytes
    ///
    /// # Example
    /// ```
    /// use rnd::RandomSource;
    ///
    /// fn rand(source: &mut dyn RandomSource) -> u32 {
    ///     let mut bytes = [0; 4];
    ///     source.fill_bytes(&mut bytes);
    ///     u32::from_le_bytes(bytes)
    /// }
    /// ```
    fn fill_bytes(&mut self, bytes: &mut [u8]);
}

/// A type that can be randomly generated.
///
/// # Example
/// ```
/// use rnd::{Random, RandomSource};
///
/// struct Point {
///     x: u32,
///     y: u32
/// }
///
/// impl Random for Point {
///     fn random<S>(source: &mut S) -> Self
///     where
///         S: RandomSource + ?Sized
///     {
///         Point {
///             x: u32::random(source),
///             y: u32::random(source),
///         }
///     }
/// }
/// ```
pub trait Random: Sized {
    fn random<S>(source: &mut S) -> Self
    where
        S: RandomSource + ?Sized;
}

/// Trait for `seedable` types.
pub trait Seedable<S> {
    fn reseed(&mut self, seed: S);
}

#[cfg(feature = "std")]
mod global;
#[cfg(feature = "std")]
pub use global::{random, set_global_random, GlobalRandomSource};