Sample from a binomial distribution. * * This is the number of successes in a sequence of independent trials with * fixed probability. * * @param n_trials The number of trials. * @param trial_prob The numerator of the probability of success of each trial. * If greater than scale, the probability is 1.0. * @param scale The denominator of trial_prob, default 100. * @return
| 389 | * @return the number of successes, range [0, n_trials] |
| 390 | */ |
| 391 | int binomial(unsigned n_trials, unsigned trial_prob, unsigned scale) |
| 392 | { |
| 393 | int count = 0; |
| 394 | for (unsigned i = 0; i < n_trials; ++i) |
| 395 | if (::x_chance_in_y(trial_prob, scale)) |
| 396 | count++; |
| 397 | |
| 398 | return count; |
| 399 | } |
| 400 | |
| 401 | // range [0, 1.0) |
| 402 | // This uses a technique described by Saito and Matsumoto at |
no test coverage detected