16template <
typename IntType>
20 :
seed_{std::random_device{}()}
34 auto bits_per_block = 8 *
sizeof(uint32_t);
35 auto blocks_per_int =
sizeof(IntType) /
sizeof(uint32_t);
36 for (
auto idx = 0; idx < blocks_per_int; ++idx) {
37 result <<= bits_per_block;
38 result |=
static_cast<IntType
>(
prng_() & 0xFFFFFFFF);
43 std::random_device::result_type
seed() {
return seed_; }
46 std::random_device::result_type
seed_;
51template <
typename IntType>
56 auto bits_per_block = 8 *
sizeof(std::random_device::result_type);
57 auto blocks_per_int =
sizeof(IntType) /
sizeof(std::random_device::result_type);
58 for (
auto idx = 0; idx < blocks_per_int; ++idx) {
59 result <<= bits_per_block;
60 result |=
static_cast<IntType
>(
rd_());
66 std::random_device
rd_;
69template <
typename IntType>
72 std::is_unsigned<IntType>::value,
73 "IntType must be an unsigned integer type."
76 sizeof(IntType) %
sizeof(std::random_device::result_type) == 0,
77 "IntType must be a multiple of the size of std::random_device::result_type."
80 constexpr size_t bits_per_block = 8 *
sizeof(std::random_device::result_type);
81 constexpr size_t bits_per_hex_digit = 4;
82 constexpr size_t hex_digits_per_block =
83 bits_per_block / bits_per_hex_digit;
84 constexpr size_t total_blocks =
85 (
sizeof(IntType) * 8 + bits_per_block - 1) /
88 std::ostringstream oss;
91 for (
int i = total_blocks - 1; i >= 0; --i) {
93 uint32_t block =
static_cast<uint32_t
>(num >> (i * bits_per_block));
95 oss << std::hex << std::setfill(
'0') << std::setw(hex_digits_per_block) << block;
100template <
typename IntType>
104 std::cout << hex_string << std::endl;
Generates pseudorandom integers.
PseudoRandomKeyGenerator()
PseudoRandomKeyGenerator(uint32_t seed)
IntType GenerateKey()
Generates a pseudorandom IntType value using mt19937.
std::random_device::result_type seed_
std::random_device::result_type seed()
Generates random integers (not pseudorandom) using std::random_device.
Calculate / manage board state and associate Minimax results.
std::string IntToHexString(IntType num)
void PrintHex(IntType num)