summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/gnuradio/gr/qa_random.py
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/python/gnuradio/gr/qa_random.py
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/python/gnuradio/gr/qa_random.py')
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/qa_random.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
index fa8c44917b..d7f4bb65a5 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_random.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
@@ -63,6 +63,42 @@ class test_random(gr_unittest.TestCase):
self.assertGreaterEqual(minimum, np.min(rnd_vals))
self.assertLess(np.max(rnd_vals), maximum)
+ def test_005_xoroshiro128p_seed_stability(self):
+ """
+ Test that seeding is stable.
+ It's basically an API break if it isn't.
+
+ We simply check for the first value of a sequence
+ being the same as it was when the module was integrated.
+ """
+ rng = gr.xoroshiro128p_prng(42)
+ self.assertEqual(3520422898491873512, rng())
+
+ def test_006_xoroshiro128p_reproducibility(self):
+ """
+ Make sure two RNGs with the same seed yield the same
+ sequence
+ """
+ seed = 123456
+ N = 10000
+ rng1 = gr.xoroshiro128p_prng(123456)
+ rng2 = gr.xoroshiro128p_prng(123456)
+ self.assertSequenceEqual(
+ tuple(rng1() for _ in range(N)),
+ tuple(rng2() for _ in range(N)))
+
+ def test_007_xoroshiro128p_range(self):
+ """
+ Check bounds.
+ Check whether a long sequence of values are within that bounds.
+ """
+ N = 10**6
+
+ self.assertEqual(gr.xoroshiro128p_prng.min(), 0)
+ self.assertEqual(gr.xoroshiro128p_prng.max(), 2**64-1)
+ rng = gr.xoroshiro128p_prng(42)
+ arr = all((0 <= rng() <= 2**64 - 1 for _ in range(N)))
+ self.assertTrue(arr)
if __name__ == '__main__':
gr_unittest.run(test_random)