Function malachite_base::num::random::striped::striped_random_unsigned_vecs
source · [−]pub fn striped_random_unsigned_vecs<T: PrimitiveUnsigned>(
seed: Seed,
mean_stripe_numerator: u64,
mean_stripe_denominator: u64,
mean_length_numerator: u64,
mean_length_denominator: u64
) -> StripedRandomUnsignedVecs<T, GeometricRandomNaturalValues<u64>>ⓘNotable traits for StripedRandomUnsignedVecs<T, I>impl<T: PrimitiveUnsigned, I: Iterator<Item = u64>> Iterator for StripedRandomUnsignedVecs<T, I> type Item = Vec<T>;
Expand description
Generates random striped Vec
s of unsigneds.
See here for more information.
The lengths of the Vec
s are sampled from a geometric distribution with a specified mean
$m$, equal to mean_length_numerator / mean_length_denominator
. $m$ must be greater than 0.
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})) = \frac{m^n}{(m+1)^{n+1}}\prod_{i=0}^{n-1}P(x_i). $$
Expected complexity per iteration
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
mean_length_numerator / mean_length_denominator
.
Panics
Panics if mean_stripe_denominator
is zero, if
mean_stripe_numerator <= mean_stripe_denominator
, if mean_length_numerator
or
mean_length_denominator
are zero, or, if after being reduced to lowest terms, their sum is
greater than or equal to $2^{64}$.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::striped::striped_random_unsigned_vecs;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::{ToBinaryString, ToDebugString};
assert_eq!(
prefix_to_string(
striped_random_unsigned_vecs::<u8>(EXAMPLE_SEED, 10, 1, 2, 1)
.map(
|xs| prefix_to_string(
xs.into_iter().map(|x: u8| x.to_binary_string()),
100
)
),
10,
),
"[[0, 0, 111000, 0, 11111110, 10000001], [0], \
[11110000, 11111111, 11111111, 11111111, 11, 0, 10000000, 11111], [0], \
[10000, 0, 11111100, 11111111, 1111111, 11111000, 11, 0, 0, 10011000, 11111111, 111, 0, \
0], [], [11111111, 11111111, 11111111, 11111111, 10111111], [0, 0, 0, 11110000], \
[11111111], [], ...]"
);