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