Exemplo n.º 1
0
 def do_test_state(self, mt):
     # States are the same except first part, which can not be recover
     self.assertListEqual(mt[1:],
                          mt19937.untwist(mt19937.twist(mt))[1:],
                          "test with state mt == untwist(twist(mt)), mt: {}".format(mt))  # mt[0] is not recoverable
     # if you twist untwisted state, also first part must be twisted correctly
     self.assertListEqual(mt19937.twist(mt),
                          mt19937.twist(mt19937.untwist(mt19937.twist(mt))),
                          "test with state twist(mt) == twist(untwist(twist(mt))), mt: {}".format(mt))
Exemplo n.º 2
0
 def do_test_state(self, mt):
     # States are the same except first part, which can not be recover
     self.assertListEqual(
         mt[1:],
         mt19937.untwist(mt19937.twist(mt))[1:],
         "test with state mt == untwist(twist(mt)), mt: {}".format(
             mt))  # mt[0] is not recoverable
     # if you twist untwisted state, also first part must be twisted correctly
     self.assertListEqual(
         mt19937.twist(mt),
         mt19937.twist(mt19937.untwist(mt19937.twist(mt))),
         "test with state twist(mt) == twist(untwist(twist(mt))), mt: {}".
         format(mt))
Exemplo n.º 3
0
 def findSeed(self, pg):
     rn = [0] * 624
     tm = [0] * 624
     for i in range(624):
         rn[i] = pg.getNumber()
         tm[i] = mt19937.unextract_number(rn[i], i)
     mt = mt19937.untwist(tm)
     seed = mt19937.uninit(mt)
     return seed
Exemplo n.º 4
0
 def findSeed(self, pg):
     rn = [0] * 624
     tm = [0] * 624
     for i in range(624):
         rn[i] = pg.getNumber()
         tm[i] = mt19937.unextract_number(rn[i], i)
     mt = mt19937.untwist(tm)
     seed = mt19937.uninit(mt)
     return seed
Exemplo n.º 5
0
 def test_is_init(self):
     testData = [42, 4190403025, 1303704821] + [random.getrandbits(32) for _ in range(10)]
     # function init generates initial state
     for seed in testData:
         self.assertTrue(mt19937.is_init(mt19937.init(seed)))
     # function twist generates state, that is not init
     for seed in testData:
         self.assertFalse(mt19937.is_init(mt19937.twist(mt19937.init(seed))))
     # function untwist applied on one time twisted state generates initial state
     for seed in testData:
         self.assertTrue(mt19937.is_init(mt19937.untwist(mt19937.twist(mt19937.init(seed)))))
     # two times applied function twist and untwist is not working because I am loosing information from mt[0]
     for seed in testData:
         mt = mt19937.init(seed)
         mt = mt19937.twist(mt)
         mt = mt19937.twist(mt)
         mt = mt19937.untwist(mt)
         mt = mt19937.untwist(mt)
Exemplo n.º 6
0
 def test_uninit(self):
     testData = [42, 4190403025, 1303704821] + [random.getrandbits(32) for _ in range(10)]
     for seed in testData:
         # extract seed from initial state
         self.assertEqual(mt19937.uninit(mt19937.init(seed)), seed)
         # perform twist, then untwist and then extract seed
         self.assertEqual(mt19937.uninit(mt19937.untwist(mt19937.twist(mt19937.init(seed)))), seed)
         # if state is not initial None is returned
         self.assertIsNone(mt19937.uninit(mt19937.twist(mt19937.init(seed))))
Exemplo n.º 7
0
 def test_uninit(self):
     testData = [42, 4190403025, 1303704821
                 ] + [random.getrandbits(32) for _ in range(10)]
     for seed in testData:
         # extract seed from initial state
         self.assertEqual(mt19937.uninit(mt19937.init(seed)), seed)
         # perform twist, then untwist and then extract seed
         self.assertEqual(
             mt19937.uninit(
                 mt19937.untwist(mt19937.twist(mt19937.init(seed)))), seed)
         # if state is not initial None is returned
         self.assertIsNone(mt19937.uninit(mt19937.twist(
             mt19937.init(seed))))
Exemplo n.º 8
0
 def test_is_init(self):
     testData = [42, 4190403025, 1303704821
                 ] + [random.getrandbits(32) for _ in range(10)]
     # function init generates initial state
     for seed in testData:
         self.assertTrue(mt19937.is_init(mt19937.init(seed)))
     # function twist generates state, that is not init
     for seed in testData:
         self.assertFalse(mt19937.is_init(mt19937.twist(
             mt19937.init(seed))))
     # function untwist applied on one time twisted state generates initial state
     for seed in testData:
         self.assertTrue(
             mt19937.is_init(
                 mt19937.untwist(mt19937.twist(mt19937.init(seed)))))
     # two times applied function twist and untwist is not working because I am loosing information from mt[0]
     for seed in testData:
         mt = mt19937.init(seed)
         mt = mt19937.twist(mt)
         mt = mt19937.twist(mt)
         mt = mt19937.untwist(mt)
         mt = mt19937.untwist(mt)