| 93 | } |
| 94 | |
| 95 | uint64_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 | |
| 110 | int GetRandInt(int nMax) |
| 111 | { |
no test coverage detected