Changeset View
Changeset View
Standalone View
Standalone View
src/random.h
| Show First 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | uint64_t randrange(uint64_t range) noexcept { | ||||
| uint64_t ret = randbits(bits); | uint64_t ret = randbits(bits); | ||||
| if (ret <= range) { | if (ret <= range) { | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** Generate random bytes. */ | /** Generate random bytes. */ | ||||
| template <typename B = uint8_t> | template <BasicByte B = uint8_t> | ||||
| std::vector<B> randbytes(size_t len) noexcept { | std::vector<B> randbytes(size_t len) noexcept { | ||||
| std::vector<B> ret(len); | std::vector<B> ret(len); | ||||
| fillrand(MakeWritableByteSpan(ret)); | fillrand(MakeWritableByteSpan(ret)); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| /** Fill a byte Span with random bytes. */ | /** Fill a byte Span with random bytes. */ | ||||
| void fillrand(Span<std::byte> output) noexcept; | void fillrand(Span<std::byte> output) noexcept; | ||||
| ▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines | |||||