Skip to content

Commit 27cefc7

Browse files
committed
random: add a few noexcepts to FastRandomContext
1 parent b3b382d commit 27cefc7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/random.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,14 @@ uint256 GetRandHash() noexcept
652652
return hash;
653653
}
654654

655-
void FastRandomContext::RandomSeed()
655+
void FastRandomContext::RandomSeed() noexcept
656656
{
657657
uint256 seed = GetRandHash();
658658
rng.SetKey(MakeByteSpan(seed));
659659
requires_seed = false;
660660
}
661661

662-
void FastRandomContext::fillrand(Span<std::byte> output)
662+
void FastRandomContext::fillrand(Span<std::byte> output) noexcept
663663
{
664664
if (requires_seed) RandomSeed();
665665
rng.Keystream(output);

src/random.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ class FastRandomContext
150150
uint64_t bitbuf;
151151
int bitbuf_size;
152152

153-
void RandomSeed();
153+
void RandomSeed() noexcept;
154154

155-
void FillBitBuffer()
155+
void FillBitBuffer() noexcept
156156
{
157157
bitbuf = rand64();
158158
bitbuf_size = 64;
@@ -213,15 +213,15 @@ 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) noexcept
217217
{
218218
std::vector<B> ret(len);
219219
fillrand(MakeWritableByteSpan(ret));
220220
return ret;
221221
}
222222

223223
/** Fill a byte Span with random bytes. */
224-
void fillrand(Span<std::byte> output);
224+
void fillrand(Span<std::byte> output) noexcept;
225225

226226
/** Generate a random 32-bit integer. */
227227
uint32_t rand32() noexcept { return randbits(32); }
@@ -239,7 +239,7 @@ class FastRandomContext
239239

240240
/** Return the time point advanced by a uniform random duration. */
241241
template <typename Tp>
242-
Tp rand_uniform_delay(const Tp& time, typename Tp::duration range)
242+
Tp rand_uniform_delay(const Tp& time, typename Tp::duration range) noexcept
243243
{
244244
return time + rand_uniform_duration<Tp>(range);
245245
}
@@ -256,8 +256,8 @@ class FastRandomContext
256256

257257
// Compatibility with the UniformRandomBitGenerator concept
258258
typedef uint64_t result_type;
259-
static constexpr uint64_t min() { return 0; }
260-
static constexpr uint64_t max() { return std::numeric_limits<uint64_t>::max(); }
259+
static constexpr uint64_t min() noexcept { return 0; }
260+
static constexpr uint64_t max() noexcept { return std::numeric_limits<uint64_t>::max(); }
261261
inline uint64_t operator()() noexcept { return rand64(); }
262262
};
263263

0 commit comments

Comments
 (0)