summaryrefslogtreecommitdiff
path: root/src/KM_prng.cpp
diff options
context:
space:
mode:
authorcah <cah@ableton.com>2022-05-02 21:14:05 +0200
committercah <cah@ableton.com>2022-05-02 21:14:17 +0200
commitee04871698c10aa4d9736d3457bf74ff68a07b5d (patch)
tree328caee49a717e8cc835f548b1d65afb86202838 /src/KM_prng.cpp
parentb9daf31fb19ac9f95e431c5bf2cdbf4cba15683a (diff)
Use boost random for the test (repeatable) RNG rather than rand_r.
Diffstat (limited to 'src/KM_prng.cpp')
-rwxr-xr-xsrc/KM_prng.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp
index 94de208..0a5166a 100755
--- a/src/KM_prng.cpp
+++ b/src/KM_prng.cpp
@@ -40,6 +40,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
+#include <boost/random.hpp>
using namespace Kumu;
@@ -67,9 +68,11 @@ public:
AES_KEY m_Context;
byte_t m_ctr_buf[RNG_BLOCK_SIZE];
Mutex m_Lock;
- unsigned int m_cth_test_rng_state;
+ boost::random::mt19937 _test_rng;
+ boost::random::uniform_int_distribution<> _test_dist;
h__RNG()
+ : _test_dist(0, 255)
{
memset(m_ctr_buf, 0, RNG_BLOCK_SIZE);
byte_t rng_key[RNG_KEY_SIZE];
@@ -157,10 +160,8 @@ public:
if (cth_test)
{
-#ifdef __unix__
for (unsigned int i = 0; i < len; ++i)
- buf[i] = rand_r(&m_cth_test_rng_state);
-#endif
+ buf[i] = _test_dist(_test_rng);
}
#if HAVE_VALGRIND_MEMCHECK_H
@@ -171,7 +172,8 @@ public:
void reset()
{
- m_cth_test_rng_state = 1;
+ _test_rng.seed(1);
+ _test_dist.reset();
}
};