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