random_positive_finite_floats

Function random_positive_finite_floats 

Source
pub fn random_positive_finite_floats(
    seed: Seed,
    mean_sci_exponent_abs_numerator: u64,
    mean_sci_exponent_abs_denominator: u64,
    mean_precision_numerator: u64,
    mean_precision_denominator: u64,
) -> RandomPositiveFiniteFloats<RandomNaturals<GeometricRandomNaturalValues<u64>>> 
Expand description

Generates random positive finite Floats.

Simpler Floats (those with a lower absolute sci-exponent or precision) are more likely to be chosen. You can specify the mean absolute sci-exponent and precision by passing the numerators and denominators of their means.

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.

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.

§Examples

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

// The number after the '#' is the precision.
assert_eq!(
    random_positive_finite_floats(EXAMPLE_SEED, 10, 1, 10, 1)
        .take(20)
        .map(|f| ComparableFloat(f).to_string())
        .collect_vec()
        .as_slice(),
    &[
        "0.9#3",
        "1.31e-6#6",
        "0.008#1",
        "0.5#1",
        "8.214e4#13",
        "0.01558827446#29",
        "0.02#1",
        "3.41#7",
        "4.598171165#33",
        "0.000033432058#23",
        "0.339299677376#37",
        "2.66e4#7",
        "3.0e4#1",
        "1.4#8",
        "37.4#9",
        "0.2#1",
        "0.0011108#13",
        "1066.0#10",
        "0.184#7",
        "0.00133230561#28"
    ]
);