diff options
author | Adam Borowski <kilobyte@angband.pl> | 2011-06-29 18:32:12 +0200 |
---|---|---|
committer | Raphael Langella <raphael.langella@gmail.com> | 2011-07-07 22:00:51 +0200 |
commit | d61bf44b16ac0e9189417065a7ad48bb8fec2aed (patch) | |
tree | 39fecb3cf2b39da6ece6d5a917f6fe96e82e78af /crawl-ref/source/random.cc | |
parent | 7995add01b0d02635dddccc684664f677f3d0aa4 (diff) | |
download | crawl-ref-d61bf44b16ac0e9189417065a7ad48bb8fec2aed.tar.gz crawl-ref-d61bf44b16ac0e9189417065a7ad48bb8fec2aed.zip |
Fix the rate of felling trees depending on action speed.
Diffstat (limited to 'crawl-ref/source/random.cc')
-rw-r--r-- | crawl-ref/source/random.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crawl-ref/source/random.cc b/crawl-ref/source/random.cc index e2f446ea10..27614c0e07 100644 --- a/crawl-ref/source/random.cc +++ b/crawl-ref/source/random.cc @@ -1,5 +1,6 @@ #include "AppHdr.h" +#include <math.h> #include "random.h" int random_range(int low, int high) @@ -263,6 +264,21 @@ int binomial_generator(unsigned n_trials, unsigned trial_prob) return count; } +// range [0..1) +double random_real() +{ + return random_int() / 4294967296.0; +} + +// Roll n_trials, return true if at least one succeeded. n_trials might be +// not integer. +bool bernoulli(double n_trials, double trial_prob) +{ + if (n_trials <= 0 || trial_prob <= 0) + return false; + return random_real() >= pow(1 - trial_prob, n_trials); +} + bool one_chance_in(int a_million) { return (random2(a_million) == 0); |