Building a random string

How to build a string with more than 5 characters and a maximum of 15 characters using a random function in python

    import string

    letters = list(string.lowercase)
+3
source share
1 answer

After import and destination, you already have it, assuming that you want all possible lengths with the same probability:

import random

length = random.randrange(5, 16)

randstr = ''.join(random.choice(letters) for _ in range(length))
+7
source

Source: https://habr.com/ru/post/1760940/


All Articles