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

Function getRandomSeed

flow/Platform.actor.cpp:2179–2212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2177namespace platform {
2178
2179int getRandomSeed() {
2180 INJECT_FAULT(platform_error, "getRandomSeed"); // getting a random seed failed
2181 int randomSeed;
2182 int retryCount = 0;
2183
2184#ifdef _WIN32
2185 do {
2186 retryCount++;
2187 if (rand_s((unsigned int*)&randomSeed) != 0) {
2188 TraceEvent(SevError, "WindowsRandomSeedError").log();
2189 throw platform_error();
2190 }
2191 } while (randomSeed == 0 &&
2192 retryCount <
2193 FLOW_KNOBS->RANDOMSEED_RETRY_LIMIT); // randomSeed cannot be 0 since we use mersenne twister in
2194 // DeterministicRandom. Get a new one if randomSeed is 0.
2195#else
2196 int devRandom = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
2197 do {
2198 retryCount++;
2199 if (read(devRandom, &randomSeed, sizeof(randomSeed)) != sizeof(randomSeed)) {
2200 TraceEvent(SevError, "OpenURandom").GetLastError();
2201 throw platform_error();
2202 }
2203 } while (randomSeed == 0 && retryCount < FLOW_KNOBS->RANDOMSEED_RETRY_LIMIT);
2204 close(devRandom);
2205#endif
2206
2207 if (randomSeed == 0) {
2208 TraceEvent(SevError, "RandomSeedZeroError").log();
2209 throw platform_error();
2210 }
2211 return randomSeed;
2212}
2213} // namespace platform
2214
2215std::string joinPath(std::string const& directory, std::string const& filename) {

Callers 6

deterministicRandomFunction · 0.85
nondeterministicRandomFunction · 0.85
CLIOptionsClass · 0.85
setupNetworkMethod · 0.85

Calls 5

TraceEventClass · 0.85
readFunction · 0.70
openFunction · 0.50
closeFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected