| 351 | } |
| 352 | |
| 353 | uint64_t GetRand(uint64_t nMax) |
| 354 | { |
| 355 | if (nMax == 0) |
| 356 | return 0; |
| 357 | |
| 358 | // The range of the random source must be a multiple of the modulus |
| 359 | // to give every possible output value an equal possibility |
| 360 | uint64_t nRange = (std::numeric_limits<uint64_t>::max() / nMax) * nMax; |
| 361 | uint64_t nRand = 0; |
| 362 | do { |
| 363 | GetRandBytes((unsigned char*)&nRand, sizeof(nRand)); |
| 364 | } while (nRand >= nRange); |
| 365 | return (nRand % nMax); |
| 366 | } |
| 367 | |
| 368 | int GetRandInt(int nMax) |
| 369 | { |