How to generate a random letter in Python

3 Answers

0 votes
import string, random
 
random_letter = random.choice(string.ascii_letters)

print(random_letter)



'''
run:

n

'''

 



answered Sep 17, 2023 by avibootz
0 votes
import string, secrets
 
# cryptographically secure random

random_letter = secrets.choice(string.ascii_letters)

print(random_letter)



'''
run:

F

'''

 



answered Sep 17, 2023 by avibootz
0 votes
import random

def randomletter(x, y):
    return chr(random.randint(ord(x), ord(y)))
 
random_letter = randomletter('a', 'z')

print(random_letter)



'''
run:

s

'''

 



answered Sep 17, 2023 by avibootz
...