MCPcopy Index your code
hub / github.com/python/cpython / randrange_fmt

Function randrange_fmt

Lib/test/test_buffer.py:171–190  ·  view source on GitHub ↗

Return random item for a type specified by a mode and a single format character.

(mode, char, obj)

Source from the content-addressed store, hash-verified

169}
170
171def randrange_fmt(mode, char, obj):
172 """Return random item for a type specified by a mode and a single
173 format character."""
174 x = randrange(*fmtdict[mode][char])
175 if char == 'c':
176 x = bytes([x])
177 if obj == 'numpy' and x == b'\x00':
178 # https://github.com/numpy/numpy/issues/2518
179 x = b'\x01'
180 if char == '?':
181 x = bool(x)
182 if char in 'efd':
183 x = struct.pack(char, x)
184 x = struct.unpack(char, x)[0]
185 if char in 'FD':
186 y = randrange(*fmtdict[mode][char])
187 x = complex(x, y)
188 x = struct.pack(char, x)
189 x = struct.unpack(char, x)[0]
190 return x
191
192def gen_item(fmt, obj):
193 """Return single random item."""

Callers 1

gen_itemFunction · 0.85

Calls 2

unpackMethod · 0.80
packMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…