proxygen
folly::ThreadLocalPRNG Class Reference

#include <Random.h>

Public Types

using result_type = uint32_t
 

Public Member Functions

result_type operator() ()
 

Static Public Member Functions

static constexpr result_type min ()
 
static constexpr result_type max ()
 

Detailed Description

A PRNG with one instance per thread. This PRNG uses a mersenne twister random number generator and is seeded from /dev/urandom. It should not be used for anything which requires security, only for statistical randomness.

An instance of this class represents the current threads PRNG. This means copying an instance of this class across threads will result in corruption

Most users will use the Random class which implicitly creates this class. However, if you are worried about performance, you can memoize the TLS lookups that get the per thread state by manually using this class:

ThreadLocalPRNG rng; for (...) { Random::rand32(rng); }

Definition at line 52 of file Random.h.

Member Typedef Documentation

Definition at line 54 of file Random.h.

Member Function Documentation

static constexpr result_type folly::ThreadLocalPRNG::max ( )
inlinestatic

Definition at line 61 of file Random.h.

References max.

Referenced by folly::Random::randDouble().

61  {
63  }
LogLevel max
Definition: LogLevel.cpp:31
static constexpr result_type folly::ThreadLocalPRNG::min ( )
inlinestatic

Definition at line 58 of file Random.h.

References min.

Referenced by folly::Random::rand32(), folly::Random::rand64(), and folly::Random::randDouble().

58  {
60  }
LogLevel min
Definition: LogLevel.cpp:30
ThreadLocalPRNG::result_type folly::ThreadLocalPRNG::operator() ( )

Definition at line 164 of file Random.cpp.

References folly::Random::create(), and folly::pushmi::operators::get.

164  {
165  struct Wrapper {
167  };
168  using Single = SingletonThreadLocal<Wrapper, RandomTag>;
169  return Single::get().object();
170 }
std::mt19937 DefaultGenerator
Definition: Random.h:97
static RNG create()
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391

The documentation for this class was generated from the following files: