commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 04/13: add test-case for reseed feature


From: git
Subject: [Commit-gnuradio] [gnuradio] 04/13: add test-case for reseed feature
Date: Sun, 6 Sep 2015 01:19:37 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 30965aab6c6b28fabb1403c635d016fc532caa0d
Author: Stefan <address@hidden>
Date:   Tue Sep 1 17:01:29 2015 +0200

    add test-case for reseed feature
---
 gnuradio-runtime/include/gnuradio/random.h       |  4 ++-
 gnuradio-runtime/python/gnuradio/gr/qa_random.py | 38 +++++++++++++++++++-----
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/random.h 
b/gnuradio-runtime/include/gnuradio/random.h
index f15b12a..3ecdf6a 100644
--- a/gnuradio-runtime/include/gnuradio/random.h
+++ b/gnuradio-runtime/include/gnuradio/random.h
@@ -36,6 +36,8 @@
 static const int RANDOM_MAX = 2147483647; // 2^31-1
 #endif /* RANDOM_MAX */
 
+// FIXME: RANDOM_MAX still necessary? Some test-cases (use grep, e.g. in 
gr-filter or gr-atsc) use this constant, but combine it with the random() 
function from the std namespace. That should not the way to use this.
+
 #include <stdlib.h>
 #include <boost/random.hpp>
 #include <ctime>
@@ -62,7 +64,7 @@ namespace gr {
     ~random();
 
     /*!
-     * \brief Change the seed for the initialized number generator
+     * \brief Change the seed for the initialized number generator. seed = 0 
initializes the random number generator with the system time. Note that a fast 
initialization of various instances can result in the same seed.
      */
     void reseed(unsigned int seed);
 
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py 
b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
index ef85337..c0d9a7f 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_random.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
@@ -23,6 +23,7 @@
 from gnuradio import gr, gr_unittest
 import numpy as np
 from scipy.stats import norm, laplace, rayleigh
+#from time import sleep
 
 class test_random(gr_unittest.TestCase):
 
@@ -110,24 +111,45 @@ class test_random(gr_unittest.TestCase):
         for k in range(len(hist[0])):
             print hist[1][k], hist[1][k+1], hist[0][k], 
float(rayleigh.cdf(hist[1][k+1])-rayleigh.cdf(hist[1][k]))*self.num_tests
 
-    # Check seeds (init with time and seed as fix number, no assert)
+    # Check seeds (init with time and seed as fix number)
     def test_6(self):
         print '# TEST 6'
-        rndm0 = gr.random(0); # init with time
-        rndm1 = gr.random(42); # init with fix seed
         num = 5
 
         print 'Some random numbers in [0,1), should change every run:'
+        rndm0 = gr.random(0); # init with time
+        # NOTE: the sleep increases the executiont time massively, remove 
assert for convenience
+        #sleep(1)
+        #rndm1 = gr.random(0); # init with fix seed
         for k in range(num):
-            print rndm0.ran1(),
+            x = rndm0.ran1();
+            print x,
+        #    y = rndm1.ran1();
+        #    print x, '!=', y
+        #    self.assertNotEqual(x,y)
         print ' '
 
-        print 'Some random numbers in [0,1), should be the same every run:'
+        print 'Some random numbers in [0,1) (seed two instances), should be 
the same every run:'
+        rndm0 = gr.random(42); # init with time
+        rndm1 = gr.random(42); # init with fix seed
         for k in range(num):
-            print rndm1.ran1(),
-        print '== '
-        print '0.374540120363 0.796543002129 0.950714290142 0.183434784412 
0.731993913651'
+            x = rndm0.ran1();
+            y = rndm1.ran1();
+            print x, '=', y
+            self.assertEqual(x,y)
 
+        print 'Some random numbers in [0,1) (reseed one instance), should be 
the same every run:'
+        x = np.zeros(num)
+        y = np.zeros(num)
+        rndm0 = gr.random(42); # init with time
+        for k in range(num):
+            x[k] = rndm0.ran1();
+        rndm1.reseed(43); # init with fix seed
+        for k in range(num):
+            y[k] = rndm0.ran1();
+        for k in range(num):
+            print x[k], '!=', y[k]
+            self.assertNotEqual(x[k],y[k])
 
 if __name__ == '__main__':
     gr_unittest.run(test_random, "test_random.xml")



reply via email to

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