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
+9 -8
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)
@@ -38,13 +38,14 @@ int main()
// populate c
std::mt19937 gen{92748}; // some arbitrary random seed
std::uniform_real_distribution<> rnd;
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
auto r=rnd(gen);
if(r<1.0/3)c.insert(warrior{i});
else if(r<2.0/3)c.insert(juggernaut{i});
else c.insert(goblin{i});
std::mt19937 gen{92748}; // some arbitrary random seed
std::discrete_distribution<> rnd({1,1,1});
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
switch(rnd(gen)){
case 0: c.insert(warrior{i});break;
case 1: c.insert(juggernaut{i});break;
case 2: c.insert(goblin{i});break;
}
}
auto render1=[](const boost::base_collection<sprite>& c){
+9 -8
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)
@@ -42,13 +42,14 @@ int main()
//[basic_any_3
// populate with sprites
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)c.insert(warrior{i});
else if(r<2.0/3)c.insert(juggernaut{i});
else c.insert(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: c.insert(warrior{i});break;
case 1: c.insert(juggernaut{i});break;
case 2: c.insert(goblin{i});break;
}
}
// populate with messages
+9 -8
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)
@@ -21,13 +21,14 @@ int main()
//=
boost::base_collection<sprite> c;
std::mt19937 gen{92748}; // some arbitrary random seed
std::uniform_real_distribution<> rnd;
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
auto r=rnd(gen);
if(r<1.0/3)c.insert(warrior{i});
else if(r<2.0/3)c.insert(juggernaut{i});
else c.insert(goblin{i});
std::mt19937 gen{92748}; // some arbitrary random seed
std::discrete_distribution<> rnd({1,1,1});
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
switch(rnd(gen)){
case 0: c.insert(warrior{i});break;
case 1: c.insert(juggernaut{i});break;
case 2: c.insert(goblin{i});break;
}
}
//]
+9 -8
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
+9 -8
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)
@@ -20,13 +20,14 @@ int main()
// populate c
std::mt19937 gen{92748}; // some arbitrary random seed
std::uniform_real_distribution<> rnd;
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
auto r=rnd(gen);
if(r<1.0/3)c.insert(warrior{i});
else if(r<2.0/3)c.insert(juggernaut{i});
else c.insert(goblin{i});
std::mt19937 gen{92748}; // some arbitrary random seed
std::discrete_distribution<> rnd({1,1,1});
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
switch(rnd(gen)){
case 0: c.insert(warrior{i});break;
case 1: c.insert(juggernaut{i});break;
case 2: c.insert(goblin{i});break;
}
}
auto render=[](const boost::base_collection<sprite>& c){
+9 -8
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)
@@ -20,13 +20,14 @@ int main()
// populate c
std::mt19937 gen{92748}; // some arbitrary random seed
std::uniform_real_distribution<> rnd;
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
auto r=rnd(gen);
if(r<1.0/3)c.insert(warrior{i});
else if(r<2.0/3)c.insert(juggernaut{i});
else c.insert(goblin{i});
std::mt19937 gen{92748}; // some arbitrary random seed
std::discrete_distribution<> rnd({1,1,1});
for(int i=0;i<8;++i){ // assign each type with 1/3 probability
switch(rnd(gen)){
case 0: c.insert(warrior{i});break;
case 1: c.insert(juggernaut{i});break;
case 2: c.insert(goblin{i});break;
}
}
auto render=[](const boost::base_collection<sprite>& c){
+11 -7
View File
@@ -38,14 +38,18 @@ int main()
//<-
auto make_sprite=[]()->std::unique_ptr<sprite>{
//->
static std::mt19937 gen{92748};
static std::uniform_real_distribution<> rnd;
static int id=0;
static std::mt19937 gen{92748};
static std::discrete_distribution<> rnd({1,1,1});
static int id=0;
auto r=rnd(gen);
if(r<1.0/3)return std::make_unique<warrior>(id++);
else if(r<2.0/3)return std::make_unique<juggernaut>(id++);
else return std::make_unique<goblin>(id++);
switch(rnd(gen)){
//<-
default:
//->
case 0: return std::make_unique<warrior>(id++);break;
case 1: return std::make_unique<juggernaut>(id++);break;
case 2: return std::make_unique<goblin>(id++);break;
}
//<-
};
//->