modify randomString to remove length limitation
@@ -42,17 +42,17 @@ Seconds = TypeVar("Seconds", int, float)
def randomString(size: int = 20,
chars: str = string.ascii_letters + string.digits) -> str:
"""
- Generate a random string of the specified size.
-
- Ensure that the size is less than the length of chars as this function uses random.choice
- which uses random sampling without replacement.
+ Generate a random string of the specified size
:param size: size of the random string to generate
:param chars: the set of characters to use to generate the random string. Uses alphanumerics by default.
:return: the random string generated
"""
- assert size < len(chars), 'size should be less than the number of characters'
- return ''.join(random.sample(chars, size))
+
+ def randomChar():
+ return random.choice(chars)
+
+ return ''.join(randomChar() for _ in range(size))
def mostCommonElement(elements: Iterable[T]) -> T:
