Function malachite_base::num::random::random_highest_bit_set_unsigneds
source · [−]pub fn random_highest_bit_set_unsigneds<T: PrimitiveUnsigned>(
seed: Seed
) -> RandomHighestBitSetValues<RandomUnsignedBitChunks<T>>ⓘNotable traits for RandomHighestBitSetValues<I>impl<I: Iterator> Iterator for RandomHighestBitSetValues<I> where
I::Item: PrimitiveInt, type Item = I::Item;
Expand description
Uniformly generates unsigned integers whose highest bit is set.
$$ P(x) = \begin{cases} 2^{1-W} & \text{if} \quad 2^{W-1} \leq x < 2^W ,\\ 0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The output length is infinite.
Complexity per iteration
Constant time and additional memory.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::random_highest_bit_set_unsigneds;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(random_highest_bit_set_unsigneds::<u8>(EXAMPLE_SEED), 10),
"[241, 222, 151, 226, 198, 220, 180, 212, 161, 175, ...]"
)