Struct std::random::Exponential
struct Exponential<F> { ... }
Exponential distribution over the positive real numbers.
This distribution is parameterized by a rate parameter lambda
.
The rate parameter is the inverse of the mean of the distribution.
Example
use std::random::{thread_rng, Exponential};
let dist: Exponential<f64> = Exponential::new(2.0);
// Prints a random number from an exponential distribution with rate 2
println!("{}", dist.sample(thread_rng()));
Run this example
Methods
impl Exponential<F> { ... }
-
fn new(lambda: F) -> Exponential<F>
Create an exponential distribution with a given rate
lambda
. -
fn sample<R>(self: &Exponential<F>, rng: &mut R) -> F
R: Rng<R>Samples a distribution using a provided random number generator.
Mixins
impl Exponential<F> { ... }
-
mixin<R> Distribution<Exponential<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