used std::discrete_distribution rather than std::uniform_real_distribution

This commit is contained in:
joaquintides
2017-06-07 00:48:15 +02:00
parent 1fcd0d7fcf
commit fade58cd39
7 changed files with 65 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@@ -24,13 +24,14 @@ int main()
//]
// populate sprs
std::mt19937 gen{92748}; // some arbitrary random seed
std::uniform_real_distribution<> rnd;
for(int i=0;i<4;++i){ // assign each type with 1/3 probability
auto r=rnd(gen);
if(r<1.0/3)sprs.push_back(std::make_unique<warrior>(i));
else if(r<2.0/3)sprs.push_back(std::make_unique<juggernaut>(i));
else sprs.push_back(std::make_unique<goblin>(i));
std::mt19937 gen{92748}; // some arbitrary random seed
std::discrete_distribution<> rnd({1,1,1});
for(int i=0;i<4;++i){ // assign each type with 1/3 probability
switch(rnd(gen)){
case 0: sprs.push_back(std::make_unique<warrior>(i));;break;
case 1: sprs.push_back(std::make_unique<juggernaut>(i));break;
case 2: sprs.push_back(std::make_unique<goblin>(i));break;
}
}
// populate msgs