Debian Codegraph @

src/mpt/random/crand.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_RANDOM_CRAND_HPP
4 #define MPT_RANDOM_CRAND_HPP
5
6
7
8 #include "mpt/base/namespace.hpp"
9 #include "mpt/base/numeric.hpp"
10 #include "mpt/random/random.hpp"
11
12 #include <cstdlib>
13
14
15
16 namespace mpt {
17 inline namespace MPT_INLINE_NS {
18
19
20
21 class crand {
22 public:
23 using state_type = void;
24 using result_type = int;
25
26 private:
27 static void reseed(uint32 seed) {
28 std::srand(seed);
29 }
30
31 public:
32 template <typename Trd>
33 static void reseed(Trd & rd) {
34 reseed(mpt::random<uint32>(rd));
35 }
36
37 public:
38 crand() = default;
39 explicit crand(const std::string &) {
40 return;
41 }
42
43 public:
44 static MPT_CONSTEXPRINLINE result_type min() {
45 return 0;
46 }
47 static MPT_CONSTEXPRINLINE result_type max() {
48 return RAND_MAX;
49 }
50 static MPT_CONSTEXPRINLINE int result_bits() {
51 return mpt::lower_bound_entropy_bits(RAND_MAX);
52 }
53 result_type operator()() {
54 return std::rand();
55 }
56 };
57
58
59 } // namespace MPT_INLINE_NS
60 } // namespace mpt
61
62
63
64 #endif // MPT_RANDOM_CRAND_HPP