Skip to content

Commit

Permalink
Formula engine: When possible, use synced RNG for the dice roll operator
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 18, 2016
1 parent ad6528d commit 4aa725a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/formula.cpp
Expand Up @@ -19,6 +19,7 @@
#include "formula_callable.hpp"
#include "formula_function.hpp"
#include "map_utils.hpp"
#include "random_new.hpp"

#include <boost/foreach.hpp>

Expand Down Expand Up @@ -409,8 +410,11 @@ class operator_expression : public formula_expression {
static int dice_roll(int num_rolls, int faces) {
int res = 0;
while(faces > 0 && num_rolls-- > 0) {
// TODO: should we use the synced rng here ?
res += (rand()%faces)+1;
if(random_new::generator) {
res += (random_new::generator->next_random() % faces) + 1;
} else {
res += (rand() % faces) + 1;
}
}
return res;
}
Expand Down

0 comments on commit 4aa725a

Please sign in to comment.