Trait rand_bits::RngBits

source ·
pub trait RngBits: Rng {
    // Provided method
    fn gen_bits<T>(&mut self, bits: u8) -> 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: u8) -> 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);

Object Safety§

This trait is not object safe.

Implementors§

source§

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