The Battle for Wesnoth  1.17.0-dev
seed_rng.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /* This file selects a seed source -- "nondeterministic" random number
16  generator in boost documentation. It should be a wrapper for
17  boost::random_device on platforms where this is available, otherwise
18  it should most likely be the system time. (Currently boost::random_device
19  is available on all supported platforms.)
20 */
21 
22 #include "seed_rng.hpp"
23 
24 #include <boost/nondet_random.hpp>
25 
26 #include <sstream>
27 #include <iomanip>
28 
29 namespace seed_rng {
30 
31  uint32_t next_seed() {
32  static boost::random_device rnd_;
33  return rnd_();
34  }
35 
36  std::string next_seed_str() {
37  uint32_t random_seed_ = next_seed();
38  std::stringstream stream;
39  stream << std::setfill('0') << std::setw(sizeof(uint32_t)*2) << std::hex << random_seed_;
40 
41  return stream.str();
42  }
43 
44 } //ends seed_rng namespace
std::string next_seed_str()
Definition: seed_rng.cpp:36
uint32_t next_seed()
Definition: seed_rng.cpp:31