MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / rand_string

Function rand_string

bbot/core/helpers/misc.py:806–835  ·  view source on GitHub ↗

Generates a random string of specified length. Args: length (int, optional): The length of the random string. Defaults to 10. digits (bool, optional): Whether to include digits in the string. Defaults to True. numeric_only (bool, optional): Whether to generate a num

(length=10, digits=True, numeric_only=False)

Source from the content-addressed store, hash-verified

804
805
806def rand_string(length=10, digits=True, numeric_only=False):
807 """
808 Generates a random string of specified length.
809
810 Args:
811 length (int, optional): The length of the random string. Defaults to 10.
812 digits (bool, optional): Whether to include digits in the string. Defaults to True.
813 numeric_only (bool, optional): Whether to generate a numeric-only string. Defaults to False.
814
815 Returns:
816 str: A random string of the specified length.
817
818 Examples:
819 >>> rand_string()
820 'c4hp4i9jzx'
821 >>> rand_string(20)
822 'ap4rsdtg5iw7ey7y3oa5'
823 >>> rand_string(30, digits=False)
824 'xdmyxtglqfzqktngkesyulwbfrihva'
825 >>> rand_string(15, numeric_only=True)
826 '934857349857395'
827 """
828 if numeric_only:
829 pool = string.digits
830 elif digits:
831 pool = string.ascii_lowercase + string.digits
832 else:
833 pool = string.ascii_lowercase
834
835 return "".join(random.choice(pool) for _ in range(length))
836
837
838def truncate_string(s: str, n: int) -> str:

Callers 7

__init__Method · 0.90
_is_wildcard_zoneMethod · 0.90
tempwordlistFunction · 0.90
_scan_nameMethod · 0.90
__init__Method · 0.90
mkdirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…