We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 139e898 commit f514fd6Copy full SHA for f514fd6
rand_distr/src/zipf.rs
@@ -187,15 +187,13 @@ where F: Float, Standard: Distribution<F>
187
loop {
188
let inv_b = self.inv_cdf(rng.sample(Standard));
189
let x = (inv_b + one).floor();
190
- let numer = x.powf(-self.s);
191
- let denom = if x <= one {
192
- one / self.t
193
- } else {
194
- inv_b.powf(-self.s) / self.t
+ let mut ratio = x.powf(-self.s) * self.t;
+ if x > one {
+ ratio = ratio * inv_b.powf(self.s)
195
};
196
197
let y = rng.sample(Standard);
198
- if y < numer / denom {
+ if y < ratio {
199
return x;
200
}
201
0 commit comments