Skip to content

Commit b3b382d

Browse files
committed
random: move rand256() and randbytes() to .h file
1 parent 493a2e0 commit b3b382d

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/random.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -659,23 +659,6 @@ void FastRandomContext::RandomSeed()
659659
requires_seed = false;
660660
}
661661

662-
uint256 FastRandomContext::rand256() noexcept
663-
{
664-
uint256 ret;
665-
fillrand(MakeWritableByteSpan(ret));
666-
return ret;
667-
}
668-
669-
template <typename B>
670-
std::vector<B> FastRandomContext::randbytes(size_t len)
671-
{
672-
std::vector<B> ret(len);
673-
fillrand(MakeWritableByteSpan(ret));
674-
return ret;
675-
}
676-
template std::vector<unsigned char> FastRandomContext::randbytes(size_t);
677-
template std::vector<std::byte> FastRandomContext::randbytes(size_t);
678-
679662
void FastRandomContext::fillrand(Span<std::byte> output)
680663
{
681664
if (requires_seed) RandomSeed();

src/random.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ class FastRandomContext
213213

214214
/** Generate random bytes. */
215215
template <typename B = unsigned char>
216-
std::vector<B> randbytes(size_t len);
216+
std::vector<B> randbytes(size_t len)
217+
{
218+
std::vector<B> ret(len);
219+
fillrand(MakeWritableByteSpan(ret));
220+
return ret;
221+
}
217222

218223
/** Fill a byte Span with random bytes. */
219224
void fillrand(Span<std::byte> output);
@@ -222,7 +227,12 @@ class FastRandomContext
222227
uint32_t rand32() noexcept { return randbits(32); }
223228

224229
/** generate a random uint256. */
225-
uint256 rand256() noexcept;
230+
uint256 rand256() noexcept
231+
{
232+
uint256 ret;
233+
fillrand(MakeWritableByteSpan(ret));
234+
return ret;
235+
}
226236

227237
/** Generate a random boolean. */
228238
bool randbool() noexcept { return randbits(1); }

0 commit comments

Comments
 (0)