Function malachite_base::num::random::striped::striped_random_unsigned_vecs_min_length
source · pub fn striped_random_unsigned_vecs_min_length<T: PrimitiveUnsigned>(
seed: Seed,
min_length: u64,
mean_stripe_numerator: u64,
mean_stripe_denominator: u64,
mean_length_numerator: u64,
mean_length_denominator: u64
) -> StripedRandomUnsignedVecs<T, GeometricRandomNaturalValues<u64>> ⓘ
Expand description
Generates random striped Vec
s of unsigneds, with a minimum length.
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
min_length
.
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{(m-a)^{n-a}}{(m+1-a)^{n+1-a}}\prod_{i=0}^{n-1}P(x_i) & n \geq a \\
0 & \text{otherwise},
\end{cases}
$$
where $a$ is min_length
.
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, if their ratio is less than or equal to min_length
, or if
they are too large and manipulating them leads to arithmetic overflow.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::striped::striped_random_unsigned_vecs_min_length;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::ToBinaryString;
assert_eq!(
prefix_to_string(
striped_random_unsigned_vecs_min_length::<u8>(EXAMPLE_SEED, 2, 10, 1, 3, 1)
.map(
|xs| prefix_to_string(
xs.into_iter().map(|x: u8| x.to_binary_string()),
100
)
),
10,
),
"[[0, 0, 111000], [0, 11111100, 11, 11111111], \
[11110000, 11111111, 11111111, 11111111], [11111000, 11111111, 11111111, 11000000], \
[0, 10000, 0], [111, 0, 0, 1111], [11110000, 11111111], [11111111, 111111], \
[110, 10000000, 11111111], [11111111, 11111111], ...]"
);