Commit 06f9ac30 authored by Andrii Vasylevskyi's avatar Andrii Vasylevskyi Committed by Facebook GitHub Bot

Tiny fix for folly::Random::secureOneIn(0) case

Summary: Same code as in oneIn() explicit check for arg 0, 1.

Reviewed By: yfeldblum

Differential Revision: D25838957

fbshipit-source-id: 36ead588e435f116d0870ba45a181979c591c3f2
parent f3daf133
......@@ -159,6 +159,9 @@ class Random {
* Returns true 1/n of the time. If n == 0, always returns false
*/
static bool secureOneIn(uint32_t n) {
if (n < 2) {
return n;
}
SecureRNG<uint32_t> srng;
return rand32(0, n, srng) == 0;
}
......
......@@ -145,7 +145,9 @@ TEST(Random, sanity) {
TEST(Random, oneIn) {
for (auto i = 0; i < 10; ++i) {
EXPECT_FALSE(folly::Random::oneIn(0));
EXPECT_FALSE(folly::Random::secureOneIn(0));
EXPECT_TRUE(folly::Random::oneIn(1));
EXPECT_TRUE(folly::Random::secureOneIn(1));
}
// When using higher sampling rates, we'll just ensure that we see both
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment