Skip to content

Commit

Permalink
Use std::mt19937 instead of boost::mt19937
Browse files Browse the repository at this point in the history
I left the implementation of mt_rng and generate_salt in the campaign_server alone since in the former case,
we might just remove the class, and in the latter I don't build it.
  • Loading branch information
Vultraz committed Apr 19, 2017
1 parent 993e42d commit 392e97a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/generators/cave_map_generator.cpp
Expand Up @@ -279,7 +279,7 @@ struct passage_path_calculator : pathfind::cost_calculator
passage_path_calculator(const t_translation::ter_map& mapdata,
const t_translation::terrain_code & wall,
double laziness, size_t windiness,
boost::random::mt19937& rng) :
std::mt19937& rng) :
map_(mapdata), wall_(wall), laziness_(laziness), windiness_(windiness), rng_(rng)
{}

Expand All @@ -289,7 +289,7 @@ struct passage_path_calculator : pathfind::cost_calculator
t_translation::terrain_code wall_;
double laziness_;
size_t windiness_;
boost::random::mt19937& rng_;
std::mt19937& rng_;
};

double passage_path_calculator::cost(const map_location& loc, const double) const
Expand Down
2 changes: 1 addition & 1 deletion src/generators/cave_map_generator.hpp
Expand Up @@ -86,7 +86,7 @@ class cave_map_generator : public map_generator
std::vector<chamber> chambers_;
std::vector<passage> passages_;
config res_;
boost::random::mt19937 rng_;
std::mt19937 rng_;
};

bool on_board(const map_location& loc) const
Expand Down
2 changes: 1 addition & 1 deletion src/generators/default_map_generator_job.hpp
Expand Up @@ -56,7 +56,7 @@ class default_map_generator_job
bool generate_lake(t_translation::ter_map& terrain, int x, int y, int lake_fall_off, std::set<map_location>& locs_touched);
map_location random_point_at_side(size_t width, size_t height);

boost::random::mt19937 rng_;
std::mt19937 rng_;
const config& game_config_;

};
Expand Down
2 changes: 1 addition & 1 deletion src/random_new.cpp
Expand Up @@ -93,7 +93,7 @@ namespace random_new
* The simplified version I have written should work the same on all
* platforms, which is the most important thing for us.
* The existence of "modulo bias" seems less important when we have moved
* to boost::mt19937, since it guarantees that there are no "bad bits"
* to std::mt19937, since it guarantees that there are no "bad bits"
* and has a very large range.
*
* If a standard cross platform version becomes available then this should
Expand Down
6 changes: 3 additions & 3 deletions src/scripting/mapgen_lua_kernel.cpp
Expand Up @@ -43,7 +43,7 @@ struct lua_State;
*/
static int intf_random(lua_State *L)
{
boost::mt19937& rng = lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L).get_default_rng();
std::mt19937& rng = lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L).get_default_rng();
if(lua_isnoneornil(L, 1)) {
double r = double (rng());
double r_max = double (rng.max());
Expand Down Expand Up @@ -201,10 +201,10 @@ uint32_t mapgen_lua_kernel::get_random_seed()
}
}

boost::mt19937& mapgen_lua_kernel::get_default_rng()
std::mt19937& mapgen_lua_kernel::get_default_rng()
{
if(!default_rng_) {
default_rng_ = boost::mt19937(get_random_seed());
default_rng_ = std::mt19937(get_random_seed());
}
return *default_rng_;
}
4 changes: 2 additions & 2 deletions src/scripting/mapgen_lua_kernel.hpp
Expand Up @@ -35,11 +35,11 @@ class mapgen_lua_kernel : public lua_kernel_base {
config create_scenario(const char * prog, const config & generator, boost::optional<uint32_t> seed); // throws game::lua_error

virtual uint32_t get_random_seed();
boost::mt19937& get_default_rng();
std::mt19937& get_default_rng();
private:
void run_generator(const char * prog, const config & generator);
boost::optional<uint32_t> random_seed_;
boost::optional<boost::mt19937> default_rng_;
boost::optional<std::mt19937> default_rng_;
};

#endif
2 changes: 1 addition & 1 deletion src/tests/test_rng.cpp
Expand Up @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_SUITE( rng )
*/
BOOST_AUTO_TEST_CASE( validate_mt19937 )
{
boost::mt19937 rng;
std::mt19937 rng;
for (int i = 0; i < 9999 ; i++) {
rng();
}
Expand Down

0 comments on commit 392e97a

Please sign in to comment.