aboutsummaryrefslogtreecommitdiff
path: root/src/sample/uniform.rs
blob: 2cd3156414febaba060f686fc7ca843a10c57610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::Float;
use super::Sampler;

use rand::prelude::*;
use rand::distributions::Uniform;
use rand_pcg::Pcg32;

#[derive(Clone)]
pub struct UniformSampler {
    r: Pcg32,
    d: Uniform<Float>,
}

impl UniformSampler {
    pub fn new() -> Self {
        Self::default()
    }
}

impl Default for UniformSampler {
    fn default() -> Self {
        Self {
            r: Pcg32::seed_from_u64(1),
            d: Uniform::new(0.0, 1.0),
        }
    }
}

impl Sampler for UniformSampler {
    fn get_sample(&mut self) -> Float {
        self.d.sample(&mut self.r)
    }
}