We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a391f2c commit e956a48Copy full SHA for e956a48
src/distributions/cauchy.rs
@@ -49,13 +49,14 @@ impl Cauchy {
49
50
impl Distribution<f64> for Cauchy {
51
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 {
52
- let mut x = rng.gen::<f64>();
53
- // guard against the extremely unlikely event we get 0 or 1 from the generator
54
- while x <= 0.0 || x >= 1.0 {
+ // sample from [0, 1)
+ let mut x: f64 = rng.gen::<f64>();
+ // guard against the extremely unlikely case we get the invalid 0.5
55
+ while x == 0.5 {
56
x = rng.gen::<f64>();
57
}
58
// get standard cauchy random number
- let comp_dev = (2.0 * PI * x).tan();
59
+ let comp_dev = (PI * x).tan();
60
// shift and scale according to parameters
61
let result = self.median + self.scale * comp_dev;
62
result
0 commit comments