Merge pull request #675 from nullworks/master

Merge RNG changes
This commit is contained in:
LightCat 2019-01-06 13:26:50 +02:00 committed by GitHub
commit a2a4dfc673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,16 @@ static settings::Int namesteal{ "name.namesteal", "0" };
static std::string stolen_name;
int getRng(int min, int max)
{
static std::random_device rd;
std::uniform_int_distribution<int> unif(min, max);
static std::mt19937 rand_engine(rd());
int x = unif(rand_engine);
return x;
}
// Func to get a new entity to steal name from and returns true if a target has
// been found
bool StolenName()
@ -72,7 +82,7 @@ bool StolenName()
return false;
// Get random number that we can use with our array
int target_random_num = floor(RandFloatRange(0, potential_targets_length - 0.1F));
int target_random_num = getRng(0, potential_targets_length - 1);
// Get a idx from our random array position
int new_target = potential_targets[target_random_num];