Function nois::ints_in_range
source · pub fn ints_in_range<T>(
randomness: [u8; 32],
count: usize,
begin: T,
end: T
) -> Vec<T>where
T: SampleUniform + Int,
Expand description
Derives random integers in the range [begin, end], i.e. including both bounds.
Use this method to avoid a modulo bias.
The resulting vector will contain exactly count
elements.
Using this is potentially more efficient than multiple calls of int_in_range
.
Example
A round of Yahtzee with five dices:
use nois::ints_in_range;
let dices = ints_in_range(randomness, 5, 1, 6);
assert_eq!(dices.len(), 5);
assert!(dices[0] >= 1 && dices[0] <= 6);
assert!(dices[1] >= 1 && dices[1] <= 6);
assert!(dices[2] >= 1 && dices[2] <= 6);
assert!(dices[3] >= 1 && dices[3] <= 6);
assert!(dices[4] >= 1 && dices[4] <= 6);