random_floats

Function random_floats 

Source
pub fn random_floats(
    seed: Seed,
    mean_sci_exponent_abs_numerator: u64,
    mean_sci_exponent_abs_denominator: u64,
    mean_precision_numerator: u64,
    mean_precision_denominator: u64,
    mean_special_p_numerator: u64,
    mean_special_p_denominator: u64,
) -> WithSpecialValues<RandomFiniteFloats<RandomNaturals<GeometricRandomNaturalValues<u64>>>>
Expand description

Generates random Floats.

Simpler Floats (those with a lower absolute sci-exponent or precision) are more likely to be chosen. You can specify the numerator and denominator of the probability that a zero, an infinity, or a NaN will be generated. You can also specify the mean absolute sci-exponent and precision by passing the numerators and denominators of their means of the nonzero Floats.

But note that the specified means are only approximate, since the distributions we are sampling are truncated geometric, and their exact means are somewhat annoying to deal with. The practical implications are that

  • The actual means are slightly lower than the specified means.
  • However, increasing the specified means increases the actual means, so this still works as a mechanism for controlling the sci-exponent and precision.
  • The specified sci-exponent mean must be greater than 0 and the precision mean greater than 2, but they may be as high as you like.

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.

§Examples

use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_float::random::random_floats;
use malachite_float::ComparableFloat;

// The number after the '#' is the precision.
assert_eq!(
    random_floats(EXAMPLE_SEED, 10, 1, 10, 1, 1, 10)
        .take(50)
        .map(|f| ComparableFloat(f).to_string())
        .collect_vec()
        .as_slice(),
    &[
        "7.203#10",
        "39.2#8",
        "0.0",
        "NaN",
        "-0.00003#2",
        "-5.0e2#1",
        "-0.0879#8",
        "-95.12#17",
        "0.38077#14",
        "0.000138037#15",
        "-0.109#7",
        "-10.312#12",
        "-13.68396900512259#51",
        "Infinity",
        "-0.34#4",
        "-7.3e-12#5",
        "-394584.0#16",
        "NaN",
        "13.5#5",
        "-0.0",
        "-0.0063#5",
        "0.06#1",
        "0.18933#12",
        "0.00004#6",
        "-4.819e-8#13",
        "1.15e3#6",
        "-1.91e7#7",
        "475.734#17",
        "1.1e-6#7",
        "Infinity",
        "-24.0#3",
        "-4.0e-15#1",
        "-Infinity",
        "0.5039#11",
        "-1.0e3#3",
        "-0.0000281#6",
        "-2.0e5#2",
        "6.43178e-6#20",
        "-0.00019#5",
        "-0.0",
        "-30.0#4",
        "0.2#1",
        "-0.00629938#18",
        "4.58278771862e-6#38",
        "-0.0002707085#19",
        "0.00001313#10",
        "NaN",
        "-0.0",
        "7.0e7#1",
        "20263.5#16"
    ]
);