|
34 | 34 | #include <cstdint> |
35 | 35 | #include <random> |
36 | 36 |
|
| 37 | +#include "absl/base/config.h" |
37 | 38 | #include "absl/random/distributions.h" // IWYU pragma: export |
38 | | -#include "absl/random/internal/nonsecure_base.h" // IWYU pragma: export |
39 | | -#include "absl/random/internal/pcg_engine.h" // IWYU pragma: export |
40 | | -#include "absl/random/internal/pool_urbg.h" |
| 39 | +#include "absl/random/internal/nonsecure_base.h" |
| 40 | +#include "absl/random/internal/pcg_engine.h" |
41 | 41 | #include "absl/random/internal/randen_engine.h" |
42 | 42 | #include "absl/random/seed_sequences.h" // IWYU pragma: export |
43 | 43 |
|
@@ -95,31 +95,46 @@ ABSL_NAMESPACE_BEGIN |
95 | 95 | // types on modern x86, ARM, and PPC architectures. |
96 | 96 | // |
97 | 97 | // This type is thread-compatible, but not thread-safe. |
98 | | - |
99 | | -// --------------------------------------------------------------------------- |
100 | | -// absl::BitGen member functions |
101 | | -// --------------------------------------------------------------------------- |
102 | | - |
103 | | -// absl::BitGen::operator()() |
104 | | -// |
105 | | -// Calls the BitGen, returning a generated value. |
106 | | - |
107 | | -// absl::BitGen::min() |
108 | | -// |
109 | | -// Returns the smallest possible value from this bit generator. |
110 | | - |
111 | | -// absl::BitGen::max() |
112 | | -// |
113 | | -// Returns the largest possible value from this bit generator. |
114 | | - |
115 | | -// absl::BitGen::discard(num) |
116 | | -// |
117 | | -// Advances the internal state of this bit generator by `num` times, and |
118 | | -// discards the intermediate results. |
119 | | -// --------------------------------------------------------------------------- |
120 | | - |
121 | | -using BitGen = random_internal::NonsecureURBGBase< |
122 | | - random_internal::randen_engine<uint64_t>>; |
| 98 | +class BitGen : private random_internal::NonsecureURBGBase< |
| 99 | + random_internal::randen_engine<uint64_t>> { |
| 100 | + using Base = random_internal::NonsecureURBGBase< |
| 101 | + random_internal::randen_engine<uint64_t>>; |
| 102 | + |
| 103 | + public: |
| 104 | + using result_type = typename Base::result_type; |
| 105 | + |
| 106 | + // BitGen() |
| 107 | + // BitGen(SeedSequence seed_seq) |
| 108 | + // |
| 109 | + // Copy disallowed. |
| 110 | + // Move allowed. |
| 111 | + using Base::Base; |
| 112 | + using Base::operator=; |
| 113 | + |
| 114 | + // BitGen::min() |
| 115 | + // |
| 116 | + // Returns the smallest possible value from this bit generator. |
| 117 | + using Base::min; |
| 118 | + |
| 119 | + // BitGen::max() |
| 120 | + // |
| 121 | + // Returns the largest possible value from this bit generator. |
| 122 | + using Base::max; |
| 123 | + |
| 124 | + // BitGen::discard(num) |
| 125 | + // |
| 126 | + // Advances the internal state of this bit generator by `num` times, and |
| 127 | + // discards the intermediate results. |
| 128 | + using Base::discard; |
| 129 | + |
| 130 | + // BitGen::operator()() |
| 131 | + // |
| 132 | + // Invoke the URBG, returning a generated value. |
| 133 | + using Base::operator(); |
| 134 | + |
| 135 | + using Base::operator==; |
| 136 | + using Base::operator!=; |
| 137 | +}; |
123 | 138 |
|
124 | 139 | // ----------------------------------------------------------------------------- |
125 | 140 | // absl::InsecureBitGen |
@@ -157,32 +172,51 @@ using BitGen = random_internal::NonsecureURBGBase< |
157 | 172 | // `absl::InsecureBitGen` is not cryptographically secure. |
158 | 173 | // |
159 | 174 | // Prefer `absl::BitGen` over `absl::InsecureBitGen` as the general type is |
160 | | -// often fast enough for the vast majority of applications. |
161 | | - |
162 | | -using InsecureBitGen = |
163 | | - random_internal::NonsecureURBGBase<random_internal::pcg64_2018_engine>; |
164 | | - |
165 | | -// --------------------------------------------------------------------------- |
166 | | -// absl::InsecureBitGen member functions |
167 | | -// --------------------------------------------------------------------------- |
168 | | - |
169 | | -// absl::InsecureBitGen::operator()() |
170 | | -// |
171 | | -// Calls the InsecureBitGen, returning a generated value. |
172 | | - |
173 | | -// absl::InsecureBitGen::min() |
| 175 | +// often fast enough for the vast majority of applications. However, it is |
| 176 | +// reasonable to use `absl::InsecureBitGen` in tests or when using a URBG |
| 177 | +// in small isolated tasks such as in `std::shuffle`. |
174 | 178 | // |
175 | | -// Returns the smallest possible value from this bit generator. |
176 | | - |
177 | | -// absl::InsecureBitGen::max() |
178 | | -// |
179 | | -// Returns the largest possible value from this bit generator. |
180 | | - |
181 | | -// absl::InsecureBitGen::discard(num) |
182 | | -// |
183 | | -// Advances the internal state of this bit generator by `num` times, and |
184 | | -// discards the intermediate results. |
185 | | -// --------------------------------------------------------------------------- |
| 179 | +// This type is thread-compatible, but not thread-safe. |
| 180 | +class InsecureBitGen : private random_internal::NonsecureURBGBase< |
| 181 | + random_internal::pcg64_2018_engine> { |
| 182 | + using Base = |
| 183 | + random_internal::NonsecureURBGBase<random_internal::pcg64_2018_engine>; |
| 184 | + |
| 185 | + public: |
| 186 | + using result_type = typename Base::result_type; |
| 187 | + |
| 188 | + // InsecureBitGen() |
| 189 | + // InsecureBitGen(SeedSequence seed_seq) |
| 190 | + // |
| 191 | + // Copy disallowed. |
| 192 | + // Move allowed. |
| 193 | + using Base::Base; |
| 194 | + using Base::operator=; |
| 195 | + |
| 196 | + // InsecureBitGen::min() |
| 197 | + // |
| 198 | + // Returns the smallest possible value from this bit generator. |
| 199 | + using Base::min; |
| 200 | + |
| 201 | + // InsecureBitGen::max() |
| 202 | + // |
| 203 | + // Returns the largest possible value from this bit generator. |
| 204 | + using Base::max; |
| 205 | + |
| 206 | + // InsecureBitGen::discard(num) |
| 207 | + // |
| 208 | + // Advances the internal state of this bit generator by `num` times, and |
| 209 | + // discards the intermediate results. |
| 210 | + using Base::discard; |
| 211 | + |
| 212 | + // InsecureBitGen::operator()() |
| 213 | + // |
| 214 | + // Invoke the URBG, returning a generated value. |
| 215 | + using Base::operator(); |
| 216 | + |
| 217 | + using Base::operator==; |
| 218 | + using Base::operator!=; |
| 219 | +}; |
186 | 220 |
|
187 | 221 | ABSL_NAMESPACE_END |
188 | 222 | } // namespace absl |
|
0 commit comments