Skip to content

Commit fade43e

Browse files
author
MarcoFalke
committed
Allow FastRandomContext::randbytes for all byte types
1 parent 2cd71d3 commit fade43e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/random.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,18 @@ uint256 FastRandomContext::rand256() noexcept
589589
return ret;
590590
}
591591

592-
std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
592+
template <typename B>
593+
std::vector<B> FastRandomContext::randbytes(size_t len)
593594
{
594595
if (requires_seed) RandomSeed();
595-
std::vector<unsigned char> ret(len);
596+
std::vector<B> ret(len);
596597
if (len > 0) {
597-
rng.Keystream(ret.data(), len);
598+
rng.Keystream(UCharCast(ret.data()), len);
598599
}
599600
return ret;
600601
}
602+
template std::vector<unsigned char> FastRandomContext::randbytes(size_t);
603+
template std::vector<std::byte> FastRandomContext::randbytes(size_t);
601604

602605
void FastRandomContext::fillrand(Span<std::byte> output)
603606
{

src/random.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ class FastRandomContext
211211
}
212212

213213
/** Generate random bytes. */
214-
std::vector<unsigned char> randbytes(size_t len);
214+
template <typename B = unsigned char>
215+
std::vector<B> randbytes(size_t len);
215216

216217
/** Fill a byte Span with random bytes. */
217218
void fillrand(Span<std::byte> output);

0 commit comments

Comments
 (0)