mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
random: make GetRand() support entire range (incl. max)
The existing code uses GetRand(nMax), with a default value for nMax, where nMax is the range of values (not the maximum!) that the output is allowed to take. This will always miss the last possible value (e.g. GetRand<uint32_t>() will never return 0xffffffff). Fix this, by moving the functionality largely in RandomMixin, and also adding a separate RandomMixin::rand function, which returns a value in the entire (non-negative) range of an integer.
This commit is contained in:
parent
810cdf6b4e
commit
e2d1f84858
3 changed files with 46 additions and 39 deletions
|
|
@ -679,11 +679,6 @@ void RandAddPeriodic() noexcept
|
|||
|
||||
void RandAddEvent(const uint32_t event_info) noexcept { GetRNGState().AddEvent(event_info); }
|
||||
|
||||
uint64_t GetRandInternal(uint64_t nMax) noexcept
|
||||
{
|
||||
return FastRandomContext().randrange(nMax);
|
||||
}
|
||||
|
||||
uint256 GetRandHash() noexcept
|
||||
{
|
||||
uint256 hash;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue