mirror of
https://github.com/boostorg/poly_collection.git
synced 2026-01-23 05:42:26 +00:00
used std::discrete_distribution rather than std::uniform_real_distribution
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user