Skip to main content

striped_random_finite_floats

Function striped_random_finite_floats 

Source
pub fn striped_random_finite_floats(
    seed: Seed,
    mean_sci_exponent_abs_numerator: u64,
    mean_sci_exponent_abs_denominator: u64,
    mean_stripe_numerator: u64,
    mean_stripe_denominator: u64,
    mean_precision_numerator: u64,
    mean_precision_denominator: u64,
    zero_p_numerator: u64,
    zero_p_denominator: u64,
) -> RandomFiniteFloats<StripedRandomNaturals<GeometricRandomNaturalValues<u64>>> 
Expand description

Generates striped random finite Floats.

Zero is generated with the specified probability. If the Float to be generated is nonzero, then the actual precision is chosen from a geometric distribution with mean $m$, where $m$ is mean_stripe_numerator / mean_stripe_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 Float is generated from the sequence and a random sci-exponent.

See StripedBitSource for information about generating striped random numbers.

Both positive and negative zero are generated. NaN is not.

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_precision_numerator or mean_precision_denominator are zero, or, if after being reduced to lowest terms, their sum is greater than or equal to $2^{64}$.

use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_float::float::random::striped_random_finite_floats;
use malachite_float::ComparableFloat;

// The number after the '#' is the precision.
assert_eq!(
    striped_random_finite_floats(EXAMPLE_SEED, 10, 1, 8, 1, 16, 1, 1, 10)
        .take(20)
        .map(|f| ComparableFloat(f).to_string())
        .collect_vec()
        .as_slice(),
    &[
        "-3.89209#14",
        "-2.607703209227954e-8#47",
        "-0.093750#11",
        "527.9999997541#38",
        "-0.0005112#7",
        "1.003845#17",
        "-1.9e-6#3",
        "-524272.0#16",
        "-0.0004407074#18",
        "7.75#5",
        "0.0",
        "0.12451#12",
        "-1.9921865#21",
        "-3.2e9#2",
        "0.06250#8",
        "-0.22#3",
        "-0.015625#11",
        "-3.81e-6#4",
        "-64.000#13",
        "-4064.000#19"
    ]
);