Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
| Show First 20 Lines • Show All 666 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 FastRandomContext::rand160() noexcept { | ||||
| if (requires_seed) { | |||||
| RandomSeed(); | |||||
| } | |||||
| uint160 ret; | uint160 ret; | ||||
| rng.Keystream(MakeWritableByteSpan(ret)); | fillrand(MakeWritableByteSpan(ret)); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| uint256 FastRandomContext::rand256() noexcept { | uint256 FastRandomContext::rand256() noexcept { | ||||
| if (requires_seed) { | |||||
| RandomSeed(); | |||||
| } | |||||
| uint256 ret; | uint256 ret; | ||||
| rng.Keystream(MakeWritableByteSpan(ret)); | fillrand(MakeWritableByteSpan(ret)); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| template <typename B> std::vector<B> FastRandomContext::randbytes(size_t len) { | template <typename B> std::vector<B> FastRandomContext::randbytes(size_t len) { | ||||
| std::vector<B> ret(len); | std::vector<B> ret(len); | ||||
| fillrand(MakeWritableByteSpan(ret)); | fillrand(MakeWritableByteSpan(ret)); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines | |||||