Function malachite_nz::integer::random::striped_random_nonzero_integers
source · pub fn striped_random_nonzero_integers(
seed: Seed,
mean_stripe_numerator: u64,
mean_stripe_denominator: u64,
mean_bits_numerator: u64,
mean_bits_denominator: u64
) -> StripedRandomIntegers<GeometricRandomNonzeroSigneds<i64>> ⓘ
Expand description
Generates striped random nonzero Integer
s whose absolute values have a specified mean bit
length.
The actual signed bit length is chosen from a distribution that produces values whose mean
absolute values are $m$, where $m$ is mean_bits_numerator / mean_bits_denominator
(see
geometric_random_nonzero_signeds
); $m$ must be greater than 1. A striped bit sequence with
the given stripe parameter is generated and truncated at the bit length. The highest bit is
forced to be 1, an Integer
is generated from the sequence, and its sign is set to the sign
of the signed bit length. The resulting distribution has no mean or higher-order statistics
(unless $m < 2$, which is not typical).
The output length is infinite.
See StripedBitSource
for information about generating striped random numbers.
§Expected complexity per iteration
$T(n, m) = O(n + m)$
$M(n, m) = O(n / m)$
where $T$ is time, $M$ is additional memory, $n$ is mean_precision_numerator
, and $m$ is
mean_precision_denominator
.
§Panics
Panics if mean_stripe_denominator
is zero, if mean_stripe_numerator < mean_stripe_denominator
, if mean_bits_numerator
or mean_bits_denominator
are zero, or if
mean_bits_numerator <= mean_bits_denominator
.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::random::EXAMPLE_SEED;
use malachite_nz::integer::random::striped_random_nonzero_integers;
use malachite_nz::integer::Integer;
assert_eq!(
prefix_to_string(striped_random_nonzero_integers(EXAMPLE_SEED, 16, 1, 32, 1), 10),
"[4, 268435456, 84405977732342160290572740160760316144, -133169152, -131064, \
-2251834173421823, 1577058304, -126100789566374399, -76, 270335, ...]"
)