MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / GetRand

Function GetRand

src/commons/random.cpp:95–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95uint64_t GetRand(uint64_t nMax)
96{
97 if (nMax == 0)
98 return 0;
99
100 // The range of the random source must be a multiple of the modulus
101 // to give every possible output value an equal possibility
102 uint64_t nRange = (std::numeric_limits<uint64_t>::max() / nMax) * nMax;
103 uint64_t nRand = 0;
104 do {
105 GetRandBytes((unsigned char*)&nRand, sizeof(nRand));
106 } while (nRand >= nRange);
107 return (nRand % nMax);
108}
109
110int GetRandInt(int nMax)
111{

Callers 8

SetMethod · 0.85
ThreadDNSAddressSeedFunction · 0.85
ThreadMessageHandlerFunction · 0.85
UNLOCK_FUNCTIONMethod · 0.85
FuzzMethod · 0.85
CreateBlockRewardTxFunction · 0.85
GetRandIntFunction · 0.85
CMainParamsMethod · 0.85

Calls 1

GetRandBytesFunction · 0.85

Tested by

no test coverage detected