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

fastest.generator.byte_strings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 25
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A gen_raw_string() 0 2 1
A gen_raw_int() 0 2 1
A int_to_bytes() 0 2 1
A gen_bit_string() 0 3 1
A gen_floats() 0 2 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