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 @@ -464,6 +464,20 @@ FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDete
464464 rng.SetKey (seed.begin (), 32 );
465465}
466466
467+ FastRandomContext& FastRandomContext::operator =(FastRandomContext&& from) noexcept
468+ {
469+ requires_seed = from.requires_seed ;
470+ rng = from.rng ;
471+ std::copy (std::begin (from.bytebuf ), std::end (from.bytebuf ), std::begin (bytebuf));
472+ bytebuf_size = from.bytebuf_size ;
473+ bitbuf = from.bitbuf ;
474+ bitbuf_size = from.bitbuf_size ;
475+ from.requires_seed = true ;
476+ from.bytebuf_size = 0 ;
477+ from.bitbuf_size = 0 ;
478+ return *this ;
479+ }
480+
467481void RandomInit ()
468482{
469483 RDRandInit ();
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ class FastRandomContext {
7676 /* * Initialize with explicit seed (only for testing) */
7777 explicit FastRandomContext (const uint256& seed);
7878
79+ // Do not permit copying a FastRandomContext (move it, or create a new one to get reseeded).
80+ FastRandomContext (const FastRandomContext&) = delete ;
81+ FastRandomContext (FastRandomContext&&) = delete ;
82+ FastRandomContext& operator =(const FastRandomContext&) = delete ;
83+
84+ /* * Move a FastRandomContext. If the original one is used again, it will be reseeded. */
85+ FastRandomContext& operator =(FastRandomContext&& from) noexcept ;
86+
7987 /* * Generate a random 64-bit integer. */
8088 uint64_t rand64 ()
8189 {
You can’t perform that action at this time.
0 commit comments