rand-bits
Random number generators with a fixed number of set bits (ones).
Setup
To use this crate, add the following entry to your Cargo.toml
file in the dependencies
section:
[]
= "0.1.1"
Alternatively, you can use the cargo add
subcommand:
cargo add rand-bits
Usage
use thread_rng;
use RngBits;
let mut rng = thread_rng;
let x: u8 = rng.gen_bits; // generates a u8 with 4 set bits
assert_eq!;
let y: u16 = rng.gen_bits; // generates a u16 with 15 set bits
assert_eq!;
let z: u64 = rng.gen_bits; // generates a u64 with 1 set bits
assert_eq!;
For more usage examples, refer to the documentation available at docs.rs.
License
This crate is licensed under the MIT License.