Total Complexity | 5 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import random |
||
2 | import binascii |
||
3 | import struct |
||
4 | |||
5 | |||
6 | def gen_bit_string(length=8): |
||
7 | bitstring = ''.join([random.choice(['0', '1']) for _ in range(length)]) |
||
8 | return bitstring |
||
9 | |||
10 | |||
11 | def gen_raw_int(size=8): |
||
12 | return int(gen_bit_string(size), 2) |
||
13 | |||
14 | |||
15 | def gen_raw_string(length=8): |
||
16 | return binascii.unhexlify('%x' % gen_raw_int(length)) |
||
17 | |||
18 | |||
19 | def int_to_bytes(n, byte_order='big'): |
||
20 | return n.to_bytes(8, byte_order) |
||
21 | |||
22 | |||
23 | def gen_floats(): |
||
24 | return struct.unpack('>d', int_to_bytes(gen_raw_int()))[0] |
||
25 |