hbutils.random.binary

random_bytes

hbutils.random.binary.random_bytes(length: int = 32, allow_zero: bool = False, rnd: Optional[random.Random] = None) → bytes[source]
Overview:

Generate random bytes.

Arguments:
  • length (int): Length of bytes, default is 32.

  • allow_zero (bool): Allow 0x00 appear in the result, default is False.

  • rnd (Optional[random.Random]): Random object you used,

    default is None which means just use the default one provided by system.

Returns:
  • bytes (bytes): Random bytes.

Examples::
>>> from hbutils.random import random_bytes
>>> random_bytes()
b'\xdc\xdc$\x05\x83\x04\x812\xfd\xda^\x7f[{\xbc\x99\x88*\xab3\x87}\xd1\xab\xddc\xa2p\xb2\xcb\x07\xc5'
>>> random_bytes(64)
b"i7\x98\xd5\x81\x1d\xdb\xd8\xe1^\xf2\xe4\xbf\xe0O^\xeb\xed\xb0i\xaa\xf3\x16Jx\xf7J\xd7\xae1\x81\xc6\xad\xd21\x15\x8aX\xb6\xc7\x85\xa4\x1c{\xac^6\xdf\x03\x94kR}\x91\x96\xfe\x06{'I\xed5\x03r"