Function malachite_base::num::random::random_nonzero_finite_primitive_floats
source · [−]pub fn random_nonzero_finite_primitive_floats<T: PrimitiveFloat>(
seed: Seed
) -> NonzeroValues<RandomPrimitiveFloatInclusiveRange<T>>ⓘNotable traits for NonzeroValues<I>impl<I: Iterator> Iterator for NonzeroValues<I> where
I::Item: PartialEq<I::Item> + Zero, type Item = I::Item;
Expand description
Generates finite nonzero primitive floats.
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, 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.
Neither positive nor negative zero are generated. NaN
is not generated either.
The output length is infinite.
Expected complexity per iteration
Constant time and additional memory.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::float::NiceFloat;
use malachite_base::num::random::random_nonzero_finite_primitive_floats;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(
random_nonzero_finite_primitive_floats::<f32>(EXAMPLE_SEED).map(NiceFloat),
10
),
"[-2.3484663e-27, 2.287989e-18, -2.0729893e-12, 3.360012e28, -9.021723e-32, 3564911.2, \
-0.0000133769445, -1.8855448e18, 8.2494555e-29, 2.2178014e-38, ...]"
);