tvalentyn commented on code in PR #26697:
URL: https://github.com/apache/beam/pull/26697#discussion_r1199492867
##########
sdks/python/apache_beam/testing/test_utils_test.py:
##########
@@ -95,6 +95,43 @@ def test_cleanup_topics(self):
pub_client.delete_topic.assert_called_with(topic=topic.name)
+class LCGeneratorTest(unittest.TestCase):
+ Generator = utils.LCGenerator
+
+ def test_generator_seed_results(self):
+ generator = self.Generator()
+ generator.seed(0)
+ self.assertEqual(generator.next_int(), 4232237)
+
+ generator.seed(1)
+ self.assertEqual(generator.next_int(), -1151252339)
+ self.assertEqual(generator.next_uint(), 3745583449)
+ self.assertAlmostEqual(generator.random_sample(), 0.375548, delta=1e-6)
+ self.assertEqual(generator.rand_bytes(10), b'\xa6\x8fW\xcb\xb1\xa88]dP')
+
+ def test_generator_seed_jdk_results(self):
+ generator = self.Generator()
+ generator.seed_jdk(0)
+ self.assertEqual(generator.next_int(), -1155484576)
+
+ generator.seed_jdk(1)
+ # the first next_int after seed_jdk(1) is close to seed_jdk(0)
+ self.assertEqual(generator.next_int(), -1155869325)
Review Comment:
just curious (you probably verified this) - does the value still match the
JDK value after some large number of iteration? no need to make a test for this.
##########
sdks/python/apache_beam/testing/synthetic_pipeline.py:
##########
@@ -83,7 +91,14 @@ def bytes(self, length):
return self.getrandbits(length * 8).to_bytes(length, sys.byteorder)
-Generator = _Random
+def get_generator(seed: Optional[int] = None, algorithm: Optional[str] = None):
+ if algorithm is None or algorithm == 'builtin':
+ return _Random(seed)
+ else:
Review Comment:
Let's check or assert that algorithm=='lcg'?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]