Passed
Push — master ( 14c447...1358c6 )
by Amresh
01:20
created

fastest.generator.byte_strings.gen_raw_string()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 1
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