String Generation¶
-
string_utils.generation.
uuid
(as_hex: bool = False) → str¶ Generated an UUID string (using uuid.uuid4()).
Examples:
>>> uuid() # possible output: '97e3a716-6b33-4ab9-9bb1-8128cb24d76b' >>> uuid(as_hex=True) # possible output: '97e3a7166b334ab99bb18128cb24d76b'
- Parameters
as_hex – True to return the hex value of the UUID, False to get its default representation (default).
- Returns
uuid string.
-
string_utils.generation.
random_string
(size: int) → str¶ Returns a string of the specified size containing random characters (uppercase/lowercase ascii letters and digits).
Example:
>>> random_string(9) # possible output: "cx3QQbzYg"
- Parameters
size (int) – Desired string size
- Returns
Random string
-
string_utils.generation.
secure_random_hex
(byte_count: int) → str¶ Generates a random string using secure low level random generator (os.urandom).
Bear in mind: due to hex conversion, the returned string will have a size that is exactly the double of the given byte_count.
Example:
>>> secure_random_hex(9) # possible output: 'aac4cf1d1d87bd5036'
- Parameters
byte_count (int) – Number of random bytes to generate
- Returns
Hexadecimal string representation of generated random bytes
-
string_utils.generation.
roman_range
(stop: int, start: int = 1, step: int = 1) → Generator¶ Similarly to native Python’s range(), returns a Generator object which generates a new roman number on each iteration instead of an integer.
Example:
>>> for n in roman_range(7): print(n) >>> # prints: I, II, III, IV, V, VI, VII >>> for n in roman_range(start=7, stop=1, step=-1): print(n) >>> # prints: VII, VI, V, IV, III, II, I
- Parameters
stop – Number at which the generation must stop (must be <= 3999).
start – Number at which the generation must start (must be >= 1).
step – Increment of each generation step (default to 1).
- Returns
Generator of roman numbers.