Example #1
0
 def test_randi(self):
     s = SyncRNG(seed=123456)
     self.assertEqual(s.randi(), 959852049)
     self.assertEqual(s.randi(), 2314333085)
     self.assertEqual(s.randi(), 2255782734)
     self.assertEqual(s.randi(), 2921461239)
     self.assertEqual(s.randi(), 1024197102)
Example #2
0
def test_shuffle():
    s = SyncRNG(seed=123456)
    x = [1, 2, 3, 4, 5]
    for i in range(5):
        y = s.shuffle(x)
        x = y
        print(y)
Example #3
0
 def test_randbelow(self):
     s = SyncRNG(seed=123456)
     self.assertEqual(s.randbelow(5), 4)
     self.assertEqual(s.randbelow(5), 0)
     self.assertEqual(s.randbelow(5), 4)
     self.assertEqual(s.randbelow(5), 4)
     self.assertEqual(s.randbelow(5), 2)
Example #4
0
 def test_rand(self):
     s = SyncRNG(seed=123456)
     self.assertAlmostEqual(s.rand(), 959852049 / pow(2, 32))
     self.assertAlmostEqual(s.rand(), 2314333085 / pow(2, 32))
     self.assertAlmostEqual(s.rand(), 2255782734 / pow(2, 32))
     self.assertAlmostEqual(s.rand(), 2921461239 / pow(2, 32))
     self.assertAlmostEqual(s.rand(), 1024197102 / pow(2, 32))
Example #5
0
    def test_first_1000(self):
        s = SyncRNG(seed=0)

        here = os.path.dirname(__file__)
        test_file = os.path.join(here, "first_1000_seed_0.txt")

        with open(test_file, "r") as fid:
            for line in fid:
                exp = int(line.strip())
                self.assertTrue(exp == s.randi())
Example #6
0
def test_rand():
    s = SyncRNG(seed=123456)
    for i in range(5):
        print('%.16f' % s.rand())
Example #7
0
def test_randi():
    s = SyncRNG(seed=123456)
    for i in range(5):
        print(s.randi())
Example #8
0
def test_randbelow():
    s = SyncRNG(seed=123456)
    for i in range(5):
        print(s.randbelow(i+1))
Example #9
0
 def test_shuffle(self):
     s = SyncRNG(seed=123456)
     x = [1, 2, 3, 4, 5]
     y = s.shuffle(x)
     self.assertEqual(y, [3, 4, 1, 2, 5])