I was wondering if there is a random letter generator in Python that takes a range as parameter? For example, if I wanted a range between A and D? I know you can use this as a generator:
import random
import string
random.choice(string.ascii_letters)
But it doesn't allow you to supply it a range.
All you need to do is select the number of different random letters your want generated, what language alphabet you want and then if you want upper, lower or both cases displayed. Once this is done, all you need to do is hit the "Generate Random Letter" button and your random letters will appear.
This is a random letter generator that picks a random alphabet by using a wheel. The letter generator has several input options and text-transformation options. The letters involved are the 26 alphabets from A to Z.
Add the CHAR function to create a character. Add the randbetween function to make the character random. Add 65, 90 to make it a letter from the alphabet. Press Enter to complete the formula: =CHAR(randbetween(65,90)).
You can slice string.ascii_letters
:
random.choice(string.ascii_letters[0:4])
>>> random.choice('ABCD')
'C'
Or if it's a larger range so you don't want to type them all out:
>>> chr(random.randint(ord('I'), ord('Q')))
'O'
Ascii is represented with numbers, so you can random a number in the range that you prefer and then cast it to char.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With