Function malachite_nz::natural::random::striped_random_naturals

source ·
pub fn striped_random_naturals(
    seed: Seed,
    mean_stripe_numerator: u64,
    mean_stripe_denominator: u64,
    mean_bits_numerator: u64,
    mean_bits_denominator: u64
) -> StripedRandomNaturals<GeometricRandomNaturalValues<u64>> 
Expand description

Generates striped random Naturals with a specified mean bit length.

The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is mean_bits_numerator / mean_bits_denominator; $m$ must be greater than 0. 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, and the Natural is generated from the sequence.

See StripedBitSource for information about generating striped random numbers.

The output length is infinite.

§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 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::random::EXAMPLE_SEED;
use malachite_nz::natural::random::striped_random_naturals;
use malachite_nz::natural::Natural;

assert_eq!(
    prefix_to_string(striped_random_naturals(EXAMPLE_SEED, 16, 1, 32, 1), 10),
    "[18014656207519744, 2228160, 64, 17592184995840, 1179440951012584587264, \
    9007749010526207, 67108864, 5, 24, 34359738879, ...]"
)