Struct std::random::StandardFloat
struct StandardFloat<F> { ... }
Uniform floating point distribution over the [0, 1)
interval.
Sampling from this distribution is equivalent to calling next_float.
See also OpenClosed01 and Open01.
Example
use std::random::{thread_rng, StandardFloat};
let dist: StandardFloat<f64> = StandardFloat::new();
// Prints a random float between 0 (inclusive) and 1 (exclusive)
println!("{}", dist.sample(thread_rng()));
Run this example
Methods
impl StandardFloat<F> { ... }
-
fn new() -> StandardFloat<F>
-
fn sample<R>(self: &StandardFloat<F>, rng: &mut R) -> F
R: Rng<R>Samples a distribution using a provided random number generator.
Mixins
impl StandardFloat<F> { ... }
-
mixin<R> Distribution<StandardFloat<F>, F, R>
R: Rng<R> -
fn sample_iter(self: &Self, rng: &mut R) -> DistIterator<Self, T, R>
Raturns an iterator producing an infinite stream of values sampled from the distribution.
Example
use std::random::{thread_rng, UniformInteger}; let dist = UniformInteger::new(0..=5); // Prints 10 random numbers between 0 and 5 inclusive for i in dist.sample_iter(thread_rng()).take(10) { println!("{}", i); }
Run this example