File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 10
10
//! The binomial distribution.
11
11
12
12
use Rng ;
13
- use distributions:: Distribution ;
13
+ use distributions:: { Distribution , Uniform } ;
14
14
15
15
/// The binomial distribution `Binomial(n, p)`.
16
16
///
@@ -139,11 +139,14 @@ impl Distribution<u64> for Binomial {
139
139
// return value
140
140
let mut y: i64 ;
141
141
142
+ let gen_u = Uniform :: new ( 0. , p4) ;
143
+ let gen_v = Uniform :: new ( 0. , 1. ) ;
144
+
142
145
loop {
143
146
// Step 1: Generate `u` for selecting the region. If region 1 is
144
147
// selected, generate a triangularly distributed variate.
145
- let u = rng . gen_range ( 0. , p4 ) ;
146
- let mut v = rng . gen_range ( 0. , 1. ) ;
148
+ let u = gen_u . sample ( rng ) ;
149
+ let mut v = gen_v . sample ( rng ) ;
147
150
if !( u > p1) {
148
151
y = f64_to_i64 ( x_m - p1 * v + u) ;
149
152
break ;
You can’t perform that action at this time.
0 commit comments