10 examples of 'random letter python' in Python

Every line of 'random letter python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
99def gen_str(length=10, letters=string.ascii_letters+string.digits):
100 return "".join([random.choice(letters) for n in range(length)])
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10def uppercase(self, length):
11 seq = string.ascii_uppercase
12 return ''.join(random.choice(seq) for _ in range(length))
36def gen_rand(length):
37
38 output = ''
39
40 while True:
41
42 for n in range(0,length):
43
44 if randint(0,1):
45 output += str(randint(0,9))
46 else:
47 output += ASCII[randint(0,ASCII.__len__()-1)]
48
49 if output not in USED_VALUES: return output
13def draw_letters():
14 """Pick NUM_LETTERS letters randomly. Hint: use stdlib random"""
15 return random.sample(POUCH, NUM_LETTERS)
5def rand():
6 chars = string.ascii_uppercase + string.digits
7 return ''.join(random.SystemRandom().choice(chars) for _ in range(32))
15def random_uppercase():
16 return random.choice(string.ascii_uppercase)
138def random_string(length, alphabet=None, lowercase=True, uppercase=True,
139 digits=True, special=True, extra=''):
140 if alphabet is not None:
141 src = alphabet
142 else:
143 src = extra
144 if lowercase:
145 src += string.ascii_lowercase
146 if uppercase:
147 src += string.ascii_uppercase
148 if digits:
149 src += string.digits
150 if special:
151 src += '!@#$%^&*()_-+=?/><,.|":;`~'
152
153 return ''.join(random.choice(src) for x in range(length))
68def random_string():
69 return ''.join(random.choices(string.ascii_lowercase, k=random.randint(4, 10)))
48def _randomString():
49 """Random string for message signing"""
50
51 return ''.join(
52 random.choice(string.ascii_uppercase + string.digits)
53 for x in range(10))
39def rand_alpha(length=0, seed=None):
40 """
41 Create a random string ONLY with letters
42
43 :return: A random string only composed by letters.
44 """
45 rnd = get_random_instance(seed)
46 length = length or rnd.randint(10, 30)
47
48 return ''.join(rnd.choice(letters) for _ in xrange(length))

Related snippets