Return random item for a type specified by a mode and a single format character.
(mode, char, obj)
| 169 | } |
| 170 | |
| 171 | def 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 | |
| 192 | def gen_item(fmt, obj): |
| 193 | """Return single random item.""" |