Function malachite_base::num::random::striped::striped_random_bool_vecs_length_range
source · [−]pub fn striped_random_bool_vecs_length_range(
seed: Seed,
a: u64,
b: u64,
mean_stripe_numerator: u64,
mean_stripe_denominator: u64
) -> StripedRandomBoolVecs<RandomUnsignedRange<u64>>ⓘNotable traits for StripedRandomBoolVecs<I>impl<I: Iterator<Item = u64>> Iterator for StripedRandomBoolVecs<I> type Item = Vec<bool>;
Expand description
Generates random striped Vec<bool>
s, with lengths in $[a, b)$.
See here for more information.
The lengths of the Vec
s are sampled from a uniform distribution on $[a, b)$. $a$ must be
less than $b$.
The mean run length (before the bit sequences are truncated) is
$m$ = mean_stripe_numerator / mean_stripe_denominator
.
$$ P((x_0, x_1, \ldots, x_{n-1})) = \begin{cases} \frac{1}{b-a}\prod_{i=0}^{n-1}P(x_i) & \text{if} \quad a \leq n < b, \\ 0 & \text{otherwise}. \end{cases} $$
Expected complexity per iteration
$T(n) = O(b)$
$M(n) = O(b)$
where $T$ is time and $M$ is additional memory.
Panics
Panics if mean_stripe_denominator
is zero, if
mean_stripe_numerator <= mean_stripe_denominator
, or if $a \geq b$.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::striped::striped_random_bool_vecs_length_range;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::ToBinaryString;
assert_eq!(
prefix_to_string(
striped_random_bool_vecs_length_range(EXAMPLE_SEED, 4, 10, 10, 1)
.map(
|bs| bs.into_iter().map(|b| if b { '1' } else { '0' }).collect::<String>()
),
20
),
"[000000000, 000000000, 000111000, 000000000, 0111, 11111, 00111111, 1000000, 00000011, \
111111111, 111111, 00000000, 00000000, 001111, 111111111, 000000000, 110000, 0001111, \
0000000, 111101111, ...]"
);