MCPcopy Create free account
hub / github.com/apache/arrow / get_random_bytes

Function get_random_bytes

python/benchmarks/common.py:40–56  ·  view source on GitHub ↗

Generate a random bytes object of size *n*. Note the result might be compressible.

(n, seed=42)

Source from the content-addressed store, hash-verified

38
39
40def get_random_bytes(n, seed=42):
41 """
42 Generate a random bytes object of size *n*.
43 Note the result might be compressible.
44 """
45 rnd = np.random.RandomState(seed)
46 # Computing a huge random bytestring can be costly, so we get at most
47 # 100KB and duplicate the result as needed
48 base_size = 100003
49 q, r = divmod(n, base_size)
50 if q == 0:
51 result = rnd.bytes(r)
52 else:
53 base = rnd.bytes(base_size)
54 result = b''.join(_multiplicate_sequence(base, n))
55 assert len(result) == n
56 return result
57
58
59def get_random_ascii(n, seed=42):

Callers 2

get_random_asciiFunction · 0.85
get_random_unicodeFunction · 0.85

Calls 4

_multiplicate_sequenceFunction · 0.85
lenFunction · 0.85
bytesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected