Expand description
Utility functions for generating random numbers with a fixed number of set bits (ones).
Example
use rand::thread_rng;
use rand_bits::RngBits;
let mut rng = thread_rng();
let x: u8 = rng.gen_bits(4); // generates a u8 with 4 set bits
assert_eq!(x.count_ones(), 4);
let y: u16 = rng.gen_bits(15); // generates a u16 with 15 set bits
assert_eq!(y.count_ones(), 15);
let z: u64 = rng.gen_bits(1); // generates a u64 with 1 set bits
assert_eq!(z.count_ones(), 1);
License
This crate is licensed under the MIT License.
Structs
- A generic random value distribution, implemented for many primitive types. Usually generates values with a numerically uniform distribution, and with a range appropriate to the type.
Traits
- Types (distributions) that can be used to create a random instance of
T
. - An automatically-implemented extension trait on
rand::Rng
.