diff options
author | reaverb <reaverb.Crawl@gmail.com> | 2014-05-10 18:31:54 -0400 |
---|---|---|
committer | reaverb <reaverb.Crawl@gmail.com> | 2014-05-10 18:40:52 -0400 |
commit | b9c215d3f3cf27d717c499f26b707bcb7a9b5031 (patch) | |
tree | b267f3cbd80450567f423a21f7a76b808e60c109 /crawl-ref/source/random.cc | |
parent | 2b8d6ef895db6532c4cff4c65f920d33580d527f (diff) | |
download | crawl-ref-b9c215d3f3cf27d717c499f26b707bcb7a9b5031.tar.gz crawl-ref-b9c215d3f3cf27d717c499f26b707bcb7a9b5031.zip |
New function: percent_chance()
Designed to make sure things like no god protecting you from miscasts
won't happen again.
Lua could use it in a couple places, if the function was made accessible from that environment.
Diffstat (limited to 'crawl-ref/source/random.cc')
-rw-r--r-- | crawl-ref/source/random.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/crawl-ref/source/random.cc b/crawl-ref/source/random.cc index a330791852..46490d609a 100644 --- a/crawl-ref/source/random.cc +++ b/crawl-ref/source/random.cc @@ -378,6 +378,11 @@ int fuzz_value(int val, int lowfuzz, int highfuzz, int naverage) return val + random2avg(lfuzz + hfuzz + 1, naverage) - lfuzz; } +bool percent_chance(double percent) +{ + return random_real() < percent; +} + // This is used when the front-end randomness is inconclusive. There are // never more than two possibilities, which simplifies things. bool defer_rand::x_chance_in_y_contd(int x, int y, int index) |