octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #58800] BIST for rng sometimes fails


From: Rik
Subject: [Octave-bug-tracker] [bug #58800] BIST for rng sometimes fails
Date: Thu, 23 Jul 2020 19:19:31 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #16, bug #58800 (project octave):

@Markus:

Most of the patch looks good.  I have a question about the random number
generation though.  The patch is


+    try
+      {
+        // The standard doesn't *guarantee* that random_device provides
+        // non-deterministic random numbers. So add entropy from this source
+        // last to make sure we gathered at least some entropy from the
earlier
+        // sources.
+        std::random_device rd;
+        std::uniform_int_distribution<uint32_t> dist (0);
+        while (n < MT_N)
+          entropy[n++] = dist (rd);
+      }


First, the default lower bound is already 0 for the uniform_int_distribution
constructor.  It might be clearer to just write


        std::uniform_int_distribution<uint32_t> dist;


Second, truly non-deterministic entropy is usually a limited resource.  The
while loop, however, is harvesting (MT_N - n) x 32 bits.  MT_N is 624 while n
is 4 so this is 19,840 bits.  If that amount is not available the program will
likely throw an exception.

Instead, you could just add one 32-bit value worth of entropy with


if (n < MT_N)
  entropy[n++] = static_cast<uint32_t> rd ();


That is likely enough given the other seedings with 1) current time in
seconds, 2) CPU time in microseconds, 3) fractional part of current time, 4)
PID.

Or, if you really want fill out the remaining 620 entries then use a random
number generator seeded from a single call to harvest entropy.


std::random_device rd;    // non-deterministic random data
std::mt19937 gen (rd ()); // Standard mersenne_twister_engine seeded with
rd()
std::uniform_int_distribution<uint32_t> dist;
while (n < MT_N)
  entropy[n++] = dist (gen);





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58800>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]