Trait RngBits

Source
pub trait RngBits: Rng {
    // Provided method
    fn gen_bits<T>(&mut self, bits: u32) -> T
       where Standard: Distribution<T> { ... }
}
Expand description

An automatically-implemented extension trait on rand::Rng.

§Example:

use rand_bits::RngBits;

fn foo<R>(rng: &mut R) -> u16
where
    R: RngBits + ?Sized,
{
    rng.gen_bits(16)
}

Provided Methods§

Source

fn gen_bits<T>(&mut self, bits: u32) -> T

Return a random value supporting the Standard distribution with a chosen number of bits set to active.

§Example
use rand::thread_rng;
use rand_bits::RngBits;

let mut rng = thread_rng();
let x: u32 = rng.gen_bits(11);
println!("{}", x);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<R> RngBits for R
where R: Rng,