Skip to main content

striped_random_negative_finite_floats

Function striped_random_negative_finite_floats 

Source
pub fn striped_random_negative_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,
) -> RandomNegativeFiniteFloats<StripedRandomNaturals<GeometricRandomNaturalValues<u64>>> 
Expand description

Generates striped random negative finite Floats.

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.

Neither positive nor negative zero is generated. NaN is not generated either.

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_negative_finite_floats;
use malachite_float::ComparableFloat;

// The number after the '#' is the precision.
assert_eq!(
    striped_random_negative_finite_floats(EXAMPLE_SEED, 10, 1, 8, 1, 16, 1)
        .take(20)
        .map(|f| ComparableFloat(f).to_string())
        .collect_vec()
        .as_slice(),
    &[
        "-0.938#4",
        "-1.9064e-6#11",
        "-0.0078#2",
        "-0.50#3",
        "-98332.000#21",
        "-0.014160633101709896512#60",
        "-0.023#2",
        "-2.109#8",
        "-4.000030282884437849#57",
        "-0.000057221276833275#43",
        "-0.25000005983747242139#63",
        "-24576.0#12",
        "-3.3e4#1",
        "-1.98431#16",
        "-33.500#12",
        "-0.25#1",
        "-0.00097680069#23",
        "-1279.50000#25",
        "-0.1250#7",
        "-0.0014648735386622#42"
    ]
);