@@ -184,27 +184,21 @@ class RandomMixin
184184 */
185185 RandomNumberGenerator auto & Impl () noexcept { return static_cast <T&>(*this ); }
186186
187+ protected:
188+ constexpr void FlushCache () noexcept
189+ {
190+ bitbuf = 0 ;
191+ bitbuf_size = 0 ;
192+ }
193+
187194public:
188- RandomMixin () noexcept = default ;
195+ constexpr RandomMixin () noexcept = default;
189196
190- // Do not permit copying an RNG.
197+ // Do not permit copying or moving an RNG.
191198 RandomMixin (const RandomMixin&) = delete ;
192199 RandomMixin& operator =(const RandomMixin&) = delete ;
193-
194- RandomMixin (RandomMixin&& other) noexcept : bitbuf(other.bitbuf), bitbuf_size(other.bitbuf_size)
195- {
196- other.bitbuf = 0 ;
197- other.bitbuf_size = 0 ;
198- }
199-
200- RandomMixin& operator =(RandomMixin&& other) noexcept
201- {
202- bitbuf = other.bitbuf ;
203- bitbuf_size = other.bitbuf_size ;
204- other.bitbuf = 0 ;
205- other.bitbuf_size = 0 ;
206- return *this ;
207- }
200+ RandomMixin (RandomMixin&&) = delete ;
201+ RandomMixin& operator =(RandomMixin&&) = delete ;
208202
209203 /* * Generate a random (bits)-bit integer. */
210204 uint64_t randbits (int bits) noexcept
@@ -394,13 +388,8 @@ class FastRandomContext : public RandomMixin<FastRandomContext>
394388 /* * Initialize with explicit seed (only for testing) */
395389 explicit FastRandomContext (const uint256& seed) noexcept ;
396390
397- // Do not permit copying a FastRandomContext (move it, or create a new one to get reseeded).
398- FastRandomContext (const FastRandomContext&) = delete ;
399- FastRandomContext (FastRandomContext&&) = delete ;
400- FastRandomContext& operator =(const FastRandomContext&) = delete ;
401-
402- /* * Move a FastRandomContext. If the original one is used again, it will be reseeded. */
403- FastRandomContext& operator =(FastRandomContext&& from) noexcept ;
391+ /* * Reseed with explicit seed (only for testing). */
392+ void Reseed (const uint256& seed) noexcept ;
404393
405394 /* * Generate a random 64-bit integer. */
406395 uint64_t rand64 () noexcept
@@ -440,14 +429,12 @@ class InsecureRandomContext : public RandomMixin<InsecureRandomContext>
440429 constexpr explicit InsecureRandomContext (uint64_t seedval) noexcept
441430 : m_s0(SplitMix64(seedval)), m_s1(SplitMix64(seedval)) {}
442431
443- // no copy - that is dangerous, we don't want accidentally copy the RNG and then have two streams
444- // with exactly the same results.
445- InsecureRandomContext (const InsecureRandomContext&) = delete ;
446- InsecureRandomContext& operator =(const InsecureRandomContext&) = delete ;
447-
448- // allow moves
449- InsecureRandomContext (InsecureRandomContext&&) = default ;
450- InsecureRandomContext& operator =(InsecureRandomContext&&) = default ;
432+ constexpr void Reseed (uint64_t seedval) noexcept
433+ {
434+ FlushCache ();
435+ m_s0 = SplitMix64 (seedval);
436+ m_s1 = SplitMix64 (seedval);
437+ }
451438
452439 constexpr uint64_t rand64 () noexcept
453440 {
0 commit comments