random engine¶
- group turbo_random_engine
Typedefs
-
using BitGen = random_internal::NonsecureURBGBase<random_internal::randen_engine<uint64_t>>¶
turbo::BitGenis a general-purpose random bit generator for generating random values for use within the Turbo random library.Typically, you use a bit generator in combination with a distribution to provide random values. Example:
Constructing twocpp // Create an turbo::BitGen. There is no need to seed this bit generator. turbo::BitGen gen; // Generate an integer value in the closed interval [1,6] int die_roll = turbo::uniform_int_distribution<int>(1, 6)(gen);
turbo::BitGens 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.turbo::BitGenmeets 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)turbo::BitGenis 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.
Note
This type is thread-compatible, but not thread-safe.
-
using InsecureBitGen = random_internal::NonsecureURBGBase<random_internal::pcg64_2018_engine>¶
turbo::InsecureBitGenis an efficient random bit generator for generating random values, recommended only for performance-sensitive use cases whereturbo::BitGenis not satisfactory when compute-bounded by bit generation costs.Example:
Likecpp // Create an turbo::InsecureBitGen turbo::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); }
turbo::BitGen,turbo::InsecureBitGenis 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.)turbo::InsecureBitGenmay 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 theturbo::BitGencomment.turbo::InsecureBitGenmeets 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)turbo::InsecureBitGenis not cryptographically secure.Prefer
turbo::BitGenoverturbo::InsecureBitGenas the general type is often fast enough for the vast majority of applications.Note
This type is thread-compatible, but not thread-safe.
-
using BitGen = random_internal::NonsecureURBGBase<random_internal::randen_engine<uint64_t>>¶