fastest.generator.byte_strings   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 44
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A gen_raw_string() 0 6 1
A gen_raw_int() 0 6 1
A int_to_bytes() 0 7 1
A gen_bit_string() 0 6 1
A gen_floats() 0 5 1
1
import random
2
import binascii
3
import struct
4
5
6
def gen_bit_string(length=8):
7
    """
8
    :param length: int
9
    :return: str
10
    """
11
    return ''.join([random.choice(['0', '1']) for _ in range(length)])
12
13
14
def gen_raw_int(size=8):
15
    """
16
    :param size: int
17
    :return: int
18
    """
19
    return int(gen_bit_string(size), 2)
20
21
22
def gen_raw_string(length=8):
23
    """
24
    :param length: int
25
    :return: str
26
    """
27
    return binascii.unhexlify('%x' % gen_raw_int(length))
28
29
30
def int_to_bytes(n, byte_order='big'):
31
    """
32
    :param n: int
33
    :param byte_order: str
34
    :return: str
35
    """
36
    return n.to_bytes(8, byte_order)
37
38
39
def gen_floats():
40
    """
41
    :return: float
42
    """
43
    return struct.unpack('>d', int_to_bytes(gen_raw_int()))[0]
44