An efficient random bit generator for performance-sensitive use cases.
Declared in <absl/random/random.h>
class InsecureBitGen;
absl::InsecureBitGen is recommended only for performance-sensitive use cases where absl::BitGen is not satisfactory when compute-bounded by bit generation costs.
Example:
// Create an absl::InsecureBitGen absl::InsecureBitGen gen; for (size_t i = 0; i < 1000000; i++) {
// Generate a bunch of random values from some complex distribution auto my_rnd = some_distribution(gen, 1, 1000); }
Like absl::BitGen, absl::InsecureBitGen is seeded by default with non-deterministic data to produce different sequences of random values across different instances, including different binary invocations. (This behavior is different than the standard library bit generators, which use golden values as their seeds.)
absl::InsecureBitGen may be constructed with an optional seed sequence type, conforming to [rand.req.seed_seq], which will be mixed with additional non-deterministic data, as detailed in the absl::BitGen comment.
absl::InsecureBitGen meets the requirements of the Uniform Random Bit Generator (URBG) concept as per the C++17 standard [rand.req.urng]though its implementation differs slightly with [rand.req.eng]. Like its standard library equivalents (e.g. std::mersenne_twister_engine) absl::InsecureBitGen is not cryptographically secure.
Prefer absl::BitGen over absl::InsecureBitGen as the general type is often fast enough for the vast majority of applications. However, it is reasonable to use absl::InsecureBitGen in tests or when using a URBG in small isolated tasks such as in std::shuffle.
This type is thread-compatible, but not thread-safe.
| Name | Description |
|---|---|
result_type | The type of the values produced by this bit generator. |
| Name | Description |
|---|---|
InsecureBitGen | Inherits the base constructors. |
discard | Advances the internal state of this bit generator. |
max | Returns the largest possible value from this bit generator. |
min | Returns the smallest possible value from this bit generator. |
operator!= | Compares two bit generators for inequality. |
operator() | Invokes the URBG, returning a generated value. |
operator= | Inherits the base assignment operators. |
operator== | Compares two bit generators for equality. |