Skip to content

Commit

Permalink
Use randbytes in custom LCG random generator (apache#33557)
Browse files Browse the repository at this point in the history
* It's internal and test only code, fine to change method name
  • Loading branch information
Abacn authored Jan 10, 2025
1 parent e5defdd commit 6b3bca3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PreCommit_Flink_Container.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"modification": 2
"modification": 3
}
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/testing/fast_test_utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ cdef class LCGenerator(object):
cpdef void seed_jdk(self, libc.stdint.uint64_t seed)
cpdef libc.stdint.int32_t next_int(self)
cpdef libc.stdint.uint32_t next_uint(self)
cpdef bytes rand_bytes(self, int length)
cpdef bytes randbytes(self, int length)
cpdef double random_sample(self)
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/testing/fast_test_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cdef class LCGenerator(object):
self.seed(self._seed)
return <libc.stdint.uint32_t>(self._seed >> (self._bits - 32))

cpdef bytes rand_bytes(self, int length):
cpdef bytes randbytes(self, int length):
cdef libc.stdint.int32_t ints = (length + 3) // 4
cdef char* data = <char*>libc.stdlib.malloc(ints * 4)
cdef libc.stdint.uint32_t value
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/testing/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def next_uint(self):
self.seed(self._seed)
return self._seed >> (self._bits - 32)

def rand_bytes(self, length):
def randbytes(self, length):
"""
Get random bytes of given length.
Expand Down
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/testing/test_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_generator_seed_results(self):
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')
self.assertEqual(generator.randbytes(10), b'\xa6\x8fW\xcb\xb1\xa88]dP')

def test_generator_seed_jdk_results(self):
generator = self.Generator()
Expand All @@ -119,7 +119,7 @@ def test_generator_seed_jdk_results(self):
self.assertEqual(generator.next_int(), -1155869325)
self.assertEqual(generator.next_uint(), 431529176)
self.assertAlmostEqual(generator.random_sample(), 0.410081, delta=1e-6)
self.assertEqual(generator.rand_bytes(10), b'\x92\xf9Mh\xfc\xcc,5\xf0\xb8')
self.assertEqual(generator.randbytes(10), b'\x92\xf9Mh\xfc\xcc,5\xf0\xb8')


try:
Expand Down

0 comments on commit 6b3bca3

Please sign in to comment.