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
464
464
rng.SetKey (seed.begin (), 32 );
465
465
}
466
466
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
+
467
481
void RandomInit ()
468
482
{
469
483
RDRandInit ();
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ class FastRandomContext {
76
76
/* * Initialize with explicit seed (only for testing) */
77
77
explicit FastRandomContext (const uint256& seed);
78
78
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
+
79
87
/* * Generate a random 64-bit integer. */
80
88
uint64_t rand64 ()
81
89
{
You can’t perform that action at this time.
0 commit comments