MCPcopy Create free account
hub / github.com/apple/foundationdb / randomInt64

Method randomInt64

flow/DeterministicRandom.cpp:67–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67int64_t DeterministicRandom::randomInt64(int64_t min, int64_t maxPlusOne) {
68 ASSERT(min < maxPlusOne);
69 uint64_t range;
70 if (maxPlusOne < 0)
71 range = std::abs(maxPlusOne - min);
72 else {
73 range = maxPlusOne;
74 range -= min;
75 }
76 uint64_t v = (gen64() % range);
77 int64_t i;
78 if (min < 0 && (-static_cast<uint64_t>(min + 1)) >= v)
79 i = -static_cast<int64_t>(-static_cast<uint64_t>(min + 1) - v) - 1;
80 else
81 i = v + min;
82 if (randLog && useRandLog)
83 fmt::print(randLog, "Rint64 {}\n", i);
84 return i;
85}
86
87uint32_t DeterministicRandom::randomUInt32() {
88 return gen64();

Calls 2

absFunction · 0.50
printFunction · 0.50

Tested by 5

test_implMethod · 0.64
TestSetVersionMethod · 0.64
TestSetOptionMethod · 0.64