proxygen
|
#include <Random.h>
Classes | |
class | SecureRNG |
Public Types | |
typedef std::mt19937 | DefaultGenerator |
Public Member Functions | |
template<class RNG , class > | |
auto | create () -> RNG |
Static Public Member Functions | |
static void | secureRandom (void *data, size_t len) |
template<class T > | |
static std::enable_if< std::is_integral< T >::value &&!std::is_same< T, bool >::value, T >::type | secureRandom () |
static uint32_t | secureRand32 () |
static uint32_t | secureRand32 (uint32_t max) |
static uint32_t | secureRand32 (uint32_t min, uint32_t max) |
static uint64_t | secureRand64 () |
static uint64_t | secureRand64 (uint64_t max) |
static uint64_t | secureRand64 (uint64_t min, uint64_t max) |
static bool | secureOneIn (uint32_t n) |
static double | secureRandDouble01 () |
static double | secureRandDouble (double min, double max) |
template<class RNG = DefaultGenerator, class = ValidRNG<RNG>> | |
static void | seed (RNG &rng) |
template<class RNG = DefaultGenerator, class = ValidRNG<RNG>> | |
static RNG | create () |
static uint32_t | rand32 () |
template<class RNG , class = ValidRNG<RNG>> | |
static uint32_t | rand32 (RNG &&rng) |
static uint32_t | rand32 (uint32_t max) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static uint32_t | rand32 (uint32_t max, RNG &&rng) |
static uint32_t | rand32 (uint32_t min, uint32_t max) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static uint32_t | rand32 (uint32_t min, uint32_t max, RNG &&rng) |
static uint64_t | rand64 () |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static uint64_t | rand64 (RNG &&rng) |
static uint64_t | rand64 (uint64_t max) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static uint64_t | rand64 (uint64_t max, RNG &&rng) |
static uint64_t | rand64 (uint64_t min, uint64_t max) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static uint64_t | rand64 (uint64_t min, uint64_t max, RNG &&rng) |
static bool | oneIn (uint32_t n) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static bool | oneIn (uint32_t n, RNG &&rng) |
static double | randDouble01 () |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static double | randDouble01 (RNG &&rng) |
static double | randDouble (double min, double max) |
template<class RNG = ThreadLocalPRNG, class = ValidRNG<RNG>> | |
static double | randDouble (double min, double max, RNG &&rng) |
Private Types | |
template<class RNG > | |
using | ValidRNG = typename std::enable_if< std::is_unsigned< invoke_result_t< RNG & >>::value, RNG >::type |
typedef std::mt19937 folly::Random::DefaultGenerator |
|
private |
auto folly::Random::create | ( | ) | -> RNG |
Definition at line 80 of file Random-inl.h.
References folly::test::begin(), folly::test::end(), s, and folly::detail::SeedData< RNG >::seedData.
|
static |
Create a new RNG, seeded with a good seed.
Note that you should usually use ThreadLocalPRNG unless you need reproducibility (such as during a test), in which case you'd want to create a RNG with a good seed in production, and seed it yourself in test.
Referenced by folly::ThreadLocalPRNG::operator()().
|
inlinestatic |
Returns true 1/n of the time. If n == 0, always returns false
Definition at line 311 of file Random.h.
Referenced by BENCHMARK(), folly::io::Codec::compress(), and folly::io::Codec::uncompress().
|
inlinestatic |
|
inlinestatic |
Returns a random uint32_t
Definition at line 213 of file Random.h.
Referenced by accuracy_test(), folly::AtomicUnorderedInsertMap< Key, Value, Hash, KeyEqual, SkipKeyValueDeletion, Atom, IndexType, Allocator >::allocationAttempt(), alwaysInlineTestFunc(), arrayTestFunc(), BENCHMARK(), branchTestFunc(), concurrentOps(), concurrentPopforSharedBuffer(), concurrentPush(), concurrentSizeTest(), contendedRW(), DSchedMixedTest(), folly::test::DeterministicSchedule::getRandNumber(), makeBuf(), proxygen::makeBuf(), makeRandom(), manyArgTypesTestFunc(), folly::RelaxedConcurrentPriorityQueue< T, MayBlock, SupportsSize, PopBatch, ListTargetSize, Mutex, Atom >::moundPush(), multiPusherPopper(), pointerTestFunc(), AtomicBatchDispatcherTesting::Job::preprocess(), producer_consumer_test(), folly::randomNumberSeed(), setupCharVecBenchmark(), singleThreadTest(), structTestFunc(), folly::futures::test::TEST(), folly::TEST(), TEST(), TEST_F(), testRandom(), and throughtput_test().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Returns a random uint32_t in [min, max) given a specific RNG. If min == max, returns 0.
Definition at line 253 of file Random.h.
References folly::ThreadLocalPRNG::min().
|
inlinestatic |
Returns a random uint64_t
Definition at line 263 of file Random.h.
Referenced by folly::AtomicUnorderedInsertMap< Key, Value, Hash, KeyEqual, SkipKeyValueDeletion, Atom, IndexType, Allocator >::allocationAttempt(), BENCHMARK(), proxygen::HTTP2Codec::generatePingRequest(), fizz::server::test::generateRandomString(), main(), makeBuf(), proxygen::makeBuf(), folly::io::test::CompressionVarintTest::runSimpleTest(), folly::io::test::CompressionTest::split(), TEST(), and TEST_F().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Returns a random uint64_t in [min, max). If min == max, returns 0.
Definition at line 301 of file Random.h.
References folly::ThreadLocalPRNG::min().
|
inlinestatic |
|
inlinestatic |
Returns a double in [min, max), if min == max, returns 0.
Definition at line 353 of file Random.h.
References folly::ThreadLocalPRNG::max(), and folly::ThreadLocalPRNG::min().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Get secure random bytes. (On Linux and OSX, this means /dev/urandom).
Definition at line 159 of file Random.cpp.
References folly::pushmi::operators::get.
|
inlinestatic |
Shortcut to get a secure random value of integral type.
Definition at line 112 of file Random.h.
Referenced by BENCHMARK(), proxygen::HTTP1xCodec::generateWebsocketKey(), folly::detail::SeedData< RNG >::SeedData(), wangle::ServerSocketConfig::ServerSocketConfig(), and TEST().
|
static |
(Re-)Seed an existing RNG with a good seed.
Note that you should usually use ThreadLocalPRNG unless you need reproducibility (such as during a test), in which case you'd want to create a RNG with a good seed in production, and seed it yourself in test.
Definition at line 73 of file Random-inl.h.
References folly::test::begin(), folly::test::end(), s, and folly::detail::SeedData< RNG >::seedData.