Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
| Show First 20 Lines • Show All 665 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void FastRandomContext::RandomSeed() { | void FastRandomContext::RandomSeed() { | ||||
| uint256 seed = GetRandHash(); | uint256 seed = GetRandHash(); | ||||
| rng.SetKey(MakeByteSpan(seed)); | rng.SetKey(MakeByteSpan(seed)); | ||||
| requires_seed = false; | requires_seed = false; | ||||
| } | } | ||||
| uint160 FastRandomContext::rand160() noexcept { | |||||
| uint160 ret; | |||||
| fillrand(MakeWritableByteSpan(ret)); | |||||
| return ret; | |||||
| } | |||||
| 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<uint8_t> 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) { | if (requires_seed) { | ||||
| RandomSeed(); | RandomSeed(); | ||||
| } | } | ||||
| rng.Keystream(output); | rng.Keystream(output); | ||||
| } | } | ||||
| FastRandomContext::FastRandomContext(const uint256 &seed) noexcept | FastRandomContext::FastRandomContext(const uint256 &seed) noexcept | ||||
| ▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines | |||||