diff options
author | Adam Borowski <kilobyte@angband.pl> | 2010-05-17 12:03:51 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2010-05-18 11:19:00 +0200 |
commit | 015afda211d658a8841777332de8ce5c81832e40 (patch) | |
tree | cec935b1db754b4614cb59c968ea8238498c34e6 /crawl-ref/source/random.cc | |
parent | 4e033d97f307a82b5b23763a34fcba480b441182 (diff) | |
download | crawl-ref-015afda211d658a8841777332de8ce5c81832e40.tar.gz crawl-ref-015afda211d658a8841777332de8ce5c81832e40.zip |
Optimize div_rand_round() by avoiding the costly random2() call when unnecessary.
Diffstat (limited to 'crawl-ref/source/random.cc')
-rw-r--r-- | crawl-ref/source/random.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crawl-ref/source/random.cc b/crawl-ref/source/random.cc index c3d0da288b..7544a052ed 100644 --- a/crawl-ref/source/random.cc +++ b/crawl-ref/source/random.cc @@ -199,7 +199,11 @@ void scale_dice(dice_def &dice, int threshold) // Calculates num/den and randomly adds one based on the remainder. int div_rand_round(int num, int den) { - return (num / den + (random2(den) < num % den)); + int rem = num % den; + if (rem) + return (num / den + (random2(den) < rem)); + else + return (num / den); } int bestroll(int max, int rolls) |