Exemple #1
0
 def test_2_same_seed(self):
     num = 5
     # Init with fixed seed.
     rndm0 = gr.random(42)
     rndm1 = gr.random(42)
     for k in range(num):
         x = rndm0.ran1()
         y = rndm1.ran1()
         self.assertEqual(x, y)
Exemple #2
0
 def test_1(self):
     num_tests = 10000
     values = np.zeros(num_tests)
     rndm = gr.random()
     for k in range(num_tests):
         values[k] = rndm.ran1()
     for value in values:
         self.assertLess(value, 1)
         self.assertGreaterEqual(value, 0)
Exemple #3
0
 def test_004_integer(self):
     nitems = 100000
     minimum = 2
     maximum = 42
     rng = gr.random(1, minimum, maximum)
     rnd_vals = np.zeros(nitems, dtype=int)
     for i in range(nitems):
         rnd_vals[i] = rng.ran_int()
     self.assertGreaterEqual(minimum, np.min(rnd_vals))
     self.assertLess(np.max(rnd_vals), maximum)
Exemple #4
0
    def test_2(self):
        num = 5

        rndm0 = gr.random(42); # init with time
        rndm1 = gr.random(42); # init with fix seed
        for k in range(num):
            x = rndm0.ran1();
            y = rndm1.ran1();
            self.assertEqual(x,y)

        x = np.zeros(num)
        y = np.zeros(num)
        rndm0 = gr.random(42); # init with fix seed 1
        for k in range(num):
            x[k] = rndm0.ran1();
        rndm1.reseed(43); # init with fix seed 2
        for k in range(num):
            y[k] = rndm0.ran1();
        for k in range(num):
            self.assertNotEqual(x[k],y[k])
Exemple #5
0
 def test_003_reseed(self):
     num = 5
     x = np.zeros(num)
     y = np.zeros(num)
     rndm = gr.random(43)  # init with fix seed 1
     for k in range(num):
         x[k] = rndm.ran1()
     rndm.reseed(43)  # init with fix seed 2
     for k in range(num):
         y[k] = rndm.ran1()
     self.assertFloatTuplesAlmostEqual(x, y)
from matplotlib import pyplot as plt

# NOTE: scipy and matplotlib are optional packages and not included in the default gnuradio dependencies

#*** SETUP ***#

# Number of realisations per histogram
num_tests = 1000000

# Set number of bins in histograms
uniform_num_bins = 31
gauss_num_bins = 31
rayleigh_num_bins = 31
laplace_num_bins = 31

rndm = gr.random() # instance of gnuradio random class (gr::random)

print 'All histograms contain',num_tests,'realisations.'

#*** GENERATE DATA ***#

uniform_values = np.zeros(num_tests)
gauss_values = np.zeros(num_tests)
rayleigh_values = np.zeros(num_tests)
laplace_values = np.zeros(num_tests)

for k in range(num_tests):
    uniform_values[k] = rndm.ran1()
    gauss_values[k] = rndm.gasdev()
    rayleigh_values[k] = rndm.rayleigh()
    laplace_values[k] = rndm.laplacian()