Function malachite_base::num::random::random_primitive_float_inclusive_range
source · [−]pub fn random_primitive_float_inclusive_range<T: PrimitiveFloat>(
seed: Seed,
a: T,
b: T
) -> RandomPrimitiveFloatInclusiveRange<T>ⓘNotable traits for RandomPrimitiveFloatInclusiveRange<T>impl<T: PrimitiveFloat> Iterator for RandomPrimitiveFloatInclusiveRange<T> type Item = T;
Expand description
Generates random primitive floats in the closed interval $[a, b]$.
Every float within the range has an equal probability of being chosen. This does not mean that the distribution approximates a uniform distribution over the reals. For example, if the range is $[0, 2]$, a float in $[1/4, 1/2)$ is as likely to be chosen as a float in $[1, 2)$, since these subranges contain an equal number of floats.
Positive and negative zero are treated as two distinct values, with negative zero being smaller than zero.
$a$ must be less than or equal to $b$.
NaN
is never generated.
The output length is infinite.
Expected complexity per iteration
Constant time and additional memory.
Panics
Panics if $a > b$.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::float::NiceFloat;
use malachite_base::num::random::random_primitive_float_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(
random_primitive_float_inclusive_range::<f32>(EXAMPLE_SEED, -0.1, 0.1).map(NiceFloat),
10
),
"[5.664681e-11, 1.2492925e-35, 2.3242339e-29, 4.699183e-7, -2.8244436e-36, -2.264039e-37, \
-0.0000017299129, 1.40616e-23, 2.7418007e-27, 1.5418819e-16, ...]"
);