A general‐purpose random bit generator for the Abseil random library.
Synopsis
Declared in <absl/random/random.h>
class BitGen;
Description
Typically, you use a bit generator in combination with a distribution to provide random values.
Example:
// Create an absl::BitGen. There is no need to seed this bit generator. absl::BitGen gen;
// Generate an integer value in the closed interval [1,6] int die_roll = absl::uniform_int_distribution<int>(1, 6)(gen);
absl::BitGen 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. Default construction intentionally provides no stability guarantees, to avoid accidental dependence on such a property.
absl::BitGen 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 below.
Example:
// Create an absl::BitGen using an std::seed_seq seed sequence std::seed_seq seq{1,2,3}; absl::BitGen gen_with_seed(seq);
// Generate an integer value in the closed interval [1,6] int die_roll2 = absl::uniform_int_distribution<int>(1, 6)(gen_with_seed);
Constructing two `absl::BitGen`s with the same seed sequence in the same process will produce the same sequence of variates, but need not do so across multiple processes even if they're executing the same binary.
absl::BitGen meets the requirements of the Uniform Random Bit Generator (URBG) concept as per the C++17 standard [rand.req.urng]though differs slightly with [rand.req.eng]. Like its standard library equivalents (e.g. std::mersenne_twister_engine) absl::BitGen is not cryptographically secure.
This type has been optimized to perform better than Mersenne Twister (https://en.wikipedia.org/wiki/Mersenne_Twister) and many other complex URBG types on modern x86, ARM, and PPC architectures.
This type is thread‐compatible, but not thread‐safe.
Type Aliases
Name |
Description |
The type of the values produced by this bit generator. |
Using Declarations
Name |
Description |
Inherits the base constructors. |
|
Advances the internal state of this bit generator. |
|
Returns the largest possible value from this bit generator. |
|
Returns the smallest possible value from this bit generator. |
|
Compares two bit generators for inequality. |
|
Invokes the URBG, returning a generated value. |
|
Inherits the base assignment operators. |
|
Compares two bit generators for equality. |
Created with MrDocs