mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-14 12:10:42 +02:00
random: move rand256() and randbytes() to .h file
This commit is contained in:
parent
493a2e024e
commit
b3b382dde2
@ -659,23 +659,6 @@ void FastRandomContext::RandomSeed()
|
|||||||
requires_seed = false;
|
requires_seed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 FastRandomContext::rand256() noexcept
|
|
||||||
{
|
|
||||||
uint256 ret;
|
|
||||||
fillrand(MakeWritableByteSpan(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename B>
|
|
||||||
std::vector<B> FastRandomContext::randbytes(size_t len)
|
|
||||||
{
|
|
||||||
std::vector<B> ret(len);
|
|
||||||
fillrand(MakeWritableByteSpan(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
template std::vector<unsigned char> FastRandomContext::randbytes(size_t);
|
|
||||||
template std::vector<std::byte> FastRandomContext::randbytes(size_t);
|
|
||||||
|
|
||||||
void FastRandomContext::fillrand(Span<std::byte> output)
|
void FastRandomContext::fillrand(Span<std::byte> output)
|
||||||
{
|
{
|
||||||
if (requires_seed) RandomSeed();
|
if (requires_seed) RandomSeed();
|
||||||
|
14
src/random.h
14
src/random.h
@ -213,7 +213,12 @@ public:
|
|||||||
|
|
||||||
/** Generate random bytes. */
|
/** Generate random bytes. */
|
||||||
template <typename B = unsigned char>
|
template <typename B = unsigned char>
|
||||||
std::vector<B> randbytes(size_t len);
|
std::vector<B> randbytes(size_t len)
|
||||||
|
{
|
||||||
|
std::vector<B> ret(len);
|
||||||
|
fillrand(MakeWritableByteSpan(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/** Fill a byte Span with random bytes. */
|
/** Fill a byte Span with random bytes. */
|
||||||
void fillrand(Span<std::byte> output);
|
void fillrand(Span<std::byte> output);
|
||||||
@ -222,7 +227,12 @@ public:
|
|||||||
uint32_t rand32() noexcept { return randbits(32); }
|
uint32_t rand32() noexcept { return randbits(32); }
|
||||||
|
|
||||||
/** generate a random uint256. */
|
/** generate a random uint256. */
|
||||||
uint256 rand256() noexcept;
|
uint256 rand256() noexcept
|
||||||
|
{
|
||||||
|
uint256 ret;
|
||||||
|
fillrand(MakeWritableByteSpan(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/** Generate a random boolean. */
|
/** Generate a random boolean. */
|
||||||
bool randbool() noexcept { return randbits(1); }
|
bool randbool() noexcept { return randbits(1); }
|
||||||
|
Loading…
Reference in New Issue
Block a user