hbutils.random.string

random_digits

hbutils.random.string.random_digits(length: int = 32, base: int = 10, upper: bool = False, rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random digits.

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

  • base (int): Base of the digits, should be in [2, 36], default is 10.

  • upper (bool): Upper the hex chars, 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:
  • string (str): Random digital string.

Examples::
>>> from hbutils.random import random_digits
>>> random_digits()
'53518555004529024184262875530824'
>>> random_digits(base=8)
'77337055655313664176450107031511'
>>> random_digits(48, base=8)
'130107050101775254773050732461131017135371516420'

random_bin_digits

hbutils.random.string.random_bin_digits(length: int = 32, rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random binary digits.

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

  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random binary digital string.

Examples::
>>> from hbutils.random import random_bin_digits
>>> random_bin_digits()
'11001011010101101100011010010011'
>>> random_bin_digits(48)
'010110000110101101111111011100010011101011010100'

random_hex_digits

hbutils.random.string.random_hex_digits(length: int = 32, upper: bool = False, rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random hexidecimal digits.

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

  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random hexidecimal digital string.

Examples::
>>> from hbutils.random import random_hex_digits
>>> random_hex_digits()
'bf4eadfb8c1700d74024833c3ce211a7'
>>> random_hex_digits(upper=True)
'7B85DE69A319BA132ACA27C7777A1C3E'
>>> random_hex_digits(48)
'7175a23730391687b7b5230c72d702a1664833a1c66783cc'

random_md5

hbutils.random.string.random_md5(rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random md5 string.

Arguments:
  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random md5 string.

Examples::
>>> from hbutils.random import random_md5
>>> random_md5()
'bbffd8913a7c49161ebe31b9092a9016'

random_sha1

hbutils.random.string.random_sha1(rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random sha1 string.

Arguments:
  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random sha1 string.

Examples::
>>> from hbutils.random import random_sha1
>>> random_sha1()
'13135aa6b05482dcdbc1f5a25d117298571e7fab'

random_base64

hbutils.random.string.random_base64(length: int = 64, rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random base64, may be useful when generate verification code.

Arguments:
  • length (int): Length of the original binary data, default is 64.

  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random base64 string.

Examples::
>>> from hbutils.random import random_base64
>>> random_base64()
'PJZzHkM2-DpeXn1W9b3rp0I66MnOeD-31d2XYTA3va7N8DSNmQgvIINnvDMKWaRW-WHo_ftgKHg40z7XbDupbg=='
>>> random_base64(48)
'siRZNSeytSUXlIgKYuZOzbhehhI7oabcxFDB07PkjyZ5b0DI5hGC0pqjJFlD6NGQ'

random_md5_with_timestamp

hbutils.random.string.random_md5_with_timestamp(rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random md5 string with timestamp.

Arguments:
  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random md5 string with timestamp.

Examples::
>>> from hbutils.random import random_md5_with_timestamp
>>> random_md5_with_timestamp()
'20220116233104357175_daf67fde4b758ff4aae21cc77f5ed689'

random_sha1_with_timestamp

hbutils.random.string.random_sha1_with_timestamp(rnd: Optional[random.Random] = None) → str[source]
Overview:

Create random sha1 string with timestamp.

Arguments:
  • rnd (Optional[random.Random]): Random object you used, default is None which means just use the default one provided by system.

Returns:
  • string (str): Random sha1 string with timestamp.

Examples::
>>> from hbutils.random import random_sha1_with_timestamp
>>> random_sha1_with_timestamp()
'20220116233121916685_fba840b80163b55cd2295d84286a438bf8acb7c0'