pub fn special_random_primitive_float_inclusive_range<T: PrimitiveFloat>(
    seed: Seed,
    a: T,
    b: T,
    mean_sci_exponent_numerator: u64,
    mean_sci_exponent_denominator: u64,
    mean_precision_numerator: u64,
    mean_precision_denominator: u64,
    mean_special_p_numerator: u64,
    mean_special_p_denominator: u64
) -> SpecialRandomFloatInclusiveRange<T>
Expand description

Generates random primitive floats in the closed interval $[a, b]$.

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 any special values (positive or negative zero or infinity) are generated, provided that they are in the range. You can also specify the mean absolute sci-exponent and precision by passing the numerators and denominators of their means of the finite 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 the smallest absolute value of any sci-exponent of a float in the range, and the precision mean greater than 2, but they may be as high as you like.

NaN is never generated.

The output length is infinite.

Expected complexity per iteration

Constant time and additional memory.

Panics

Panics if $a$ or $b$ are NaN, if $a$ is greater than $b$ in the NiceFloat ordering, if any of the denominators are zero, if the special probability is greater than 1, if the mean precision is less than 2, or if the mean sci-exponent is less than or equal to the minimum absolute value of any sci-exponent in the range.

Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::float::NiceFloat;
use malachite_base::num::random::special_random_primitive_float_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;

assert_eq!(
    prefix_to_string(
        special_random_primitive_float_inclusive_range::<f32>(
            EXAMPLE_SEED,
            core::f32::consts::E,
            core::f32::consts::PI,
            10,
            1,
            10,
            1,
            1,
            100
        ).map(NiceFloat),
        20
    ),
    "[2.9238281, 2.953125, 3.0, 2.8671875, 2.8125, 3.125, 3.015625, 2.8462658, 3.140625, \
    2.875, 3.0, 2.75, 3.0, 2.71875, 2.75, 3.0214844, 2.970642, 3.0179443, 2.968872, 2.75, ...]"
);