summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/math
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-03-22 00:37:47 +0100
committermormj <34754695+mormj@users.noreply.github.com>2021-04-06 07:37:17 -0400
commiteb91fb04b3d0ca8124b9bea375e3bf72963fa172 (patch)
treedcf96c9e232b7019a7d81cd16901a95bda8b5471 /gnuradio-runtime/lib/math
parent42349ff2855c1bb0148c8191339189b0a4cee675 (diff)
runtime: fix gr::random API to be fixed-width 64 bit, use XOROSHIRO128+
Seeding being inconsistent between gr::random and things like fastnoise source is an outstanding issue (#1559). Fix that by fixing the API, and pivoting to our built-in XOROSHIRO128+, which is also substantially faster than MT19937. For that purpose, introduce, and python-bind, a wrapper class that can be used with STL distribution shapers. Add a unit test for the (P)RNG. Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gnuradio-runtime/lib/math')
-rw-r--r--gnuradio-runtime/lib/math/random.cc13
1 files changed, 6 insertions, 7 deletions
diff --git a/gnuradio-runtime/lib/math/random.cc b/gnuradio-runtime/lib/math/random.cc
index 8b67532207..6423a39f6c 100644
--- a/gnuradio-runtime/lib/math/random.cc
+++ b/gnuradio-runtime/lib/math/random.cc
@@ -35,13 +35,12 @@
namespace gr {
-random::random(unsigned int seed, int min_integer, int max_integer)
- : d_rng(), d_integer_dis(0, 1)
+random::random(uint64_t seed, int64_t min_integer, int64_t max_integer)
+ : d_rng(seed), d_integer_dis(0, 1)
{
d_gauss_stored = false; // set gasdev (gauss distributed numbers) on calculation state
// Setup random number generators
- reseed(seed); // set seed for random number generator
set_integer_limits(min_integer, max_integer);
}
@@ -51,7 +50,7 @@ random::~random() {}
* Seed is initialized with time if the given seed is 0. Otherwise the seed is taken
* directly. Sets the seed for the random number generator.
*/
-void random::reseed(unsigned int seed)
+void random::reseed(uint64_t seed)
{
d_seed = seed;
if (d_seed == 0) {
@@ -63,17 +62,17 @@ void random::reseed(unsigned int seed)
}
}
-void random::set_integer_limits(const int minimum, const int maximum)
+void random::set_integer_limits(int64_t minimum, int64_t maximum)
{
// boost expects integer limits defined as [minimum, maximum] which is unintuitive.
// use the expected half open interval behavior! [minimum, maximum)!
- d_integer_dis = std::uniform_int_distribution<>(minimum, maximum - 1);
+ d_integer_dis = std::uniform_int_distribution<int64_t>(minimum, maximum - 1);
}
/*!
* Uniform random integers in the range set by 'set_integer_limits' [min, max).
*/
-int random::ran_int() { return d_integer_dis(d_rng); }
+int64_t random::ran_int() { return d_integer_dis(d_rng); }
/*
* Returns uniformly distributed numbers in [0,1) taken from boost.random using a Mersenne