Skip to content

Commit 6b3bca3

Browse files
authored
Use randbytes in custom LCG random generator (#33557)
* It's internal and test only code, fine to change method name
1 parent e5defdd commit 6b3bca3

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"comment": "Modify this file in a trivial way to cause this test suite to run",
3-
"modification": 2
3+
"modification": 3
44
}

sdks/python/apache_beam/testing/fast_test_utils.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ cdef class LCGenerator(object):
2929
cpdef void seed_jdk(self, libc.stdint.uint64_t seed)
3030
cpdef libc.stdint.int32_t next_int(self)
3131
cpdef libc.stdint.uint32_t next_uint(self)
32-
cpdef bytes rand_bytes(self, int length)
32+
cpdef bytes randbytes(self, int length)
3333
cpdef double random_sample(self)

sdks/python/apache_beam/testing/fast_test_utils.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cdef class LCGenerator(object):
4444
self.seed(self._seed)
4545
return <libc.stdint.uint32_t>(self._seed >> (self._bits - 32))
4646

47-
cpdef bytes rand_bytes(self, int length):
47+
cpdef bytes randbytes(self, int length):
4848
cdef libc.stdint.int32_t ints = (length + 3) // 4
4949
cdef char* data = <char*>libc.stdlib.malloc(ints * 4)
5050
cdef libc.stdint.uint32_t value

sdks/python/apache_beam/testing/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def next_uint(self):
273273
self.seed(self._seed)
274274
return self._seed >> (self._bits - 32)
275275

276-
def rand_bytes(self, length):
276+
def randbytes(self, length):
277277
"""
278278
Get random bytes of given length.
279279

sdks/python/apache_beam/testing/test_utils_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_generator_seed_results(self):
107107
self.assertEqual(generator.next_int(), -1151252339)
108108
self.assertEqual(generator.next_uint(), 3745583449)
109109
self.assertAlmostEqual(generator.random_sample(), 0.375548, delta=1e-6)
110-
self.assertEqual(generator.rand_bytes(10), b'\xa6\x8fW\xcb\xb1\xa88]dP')
110+
self.assertEqual(generator.randbytes(10), b'\xa6\x8fW\xcb\xb1\xa88]dP')
111111

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

124124

125125
try:

0 commit comments

Comments
 (0)