File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -462,6 +462,20 @@ FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDete
462462 rng.SetKey (seed.begin (), 32 );
463463}
464464
465+ FastRandomContext& FastRandomContext::operator =(FastRandomContext&& from) noexcept
466+ {
467+ requires_seed = from.requires_seed ;
468+ rng = from.rng ;
469+ std::copy (std::begin (from.bytebuf ), std::end (from.bytebuf ), std::begin (bytebuf));
470+ bytebuf_size = from.bytebuf_size ;
471+ bitbuf = from.bitbuf ;
472+ bitbuf_size = from.bitbuf_size ;
473+ from.requires_seed = true ;
474+ from.bytebuf_size = 0 ;
475+ from.bitbuf_size = 0 ;
476+ return *this ;
477+ }
478+
465479void RandomInit ()
466480{
467481 RDRandInit ();
Original file line number Diff line number Diff line change @@ -75,6 +75,14 @@ class FastRandomContext {
7575 /* * Initialize with explicit seed (only for testing) */
7676 explicit FastRandomContext (const uint256& seed);
7777
78+ // Do not permit copying a FastRandomContext (move it, or create a new one to get reseeded).
79+ FastRandomContext (const FastRandomContext&) = delete ;
80+ FastRandomContext (FastRandomContext&&) = delete ;
81+ FastRandomContext& operator =(const FastRandomContext&) = delete ;
82+
83+ /* * Move a FastRandomContext. If the original one is used again, it will be reseeded. */
84+ FastRandomContext& operator =(FastRandomContext&& from) noexcept ;
85+
7886 /* * Generate a random 64-bit integer. */
7987 uint64_t rand64 ()
8088 {
You can’t perform that action at this time.
0 commit comments