ADded word generator.
This commit is contained in:
parent
dc95604289
commit
4532cc4637
30
word_generator.py
Normal file
30
word_generator.py
Normal file
@ -0,0 +1,30 @@
|
||||
# TO USE FOR FRIENDLY URLS OR SO. IT'S MADE TO EASY REMEMBER.
|
||||
|
||||
import random
|
||||
import string
|
||||
|
||||
# Good for 25181030 words
|
||||
|
||||
class WordGenerator:
|
||||
def __init__(self):
|
||||
self.syllables = ['ba', 'be', 'bi', 'bo', 'bu', 'ka', 'ke', 'ki', 'ko', 'ku', 'la', 'le', 'li', 'lo', 'lu', 'ma', 'me', 'mi', 'mo', 'mu', 'na', 'ne', 'ni', 'no', 'nu', 'ra', 're', 'ri', 'ro', 'ru']
|
||||
|
||||
def generate_word(self, length=8):
|
||||
word = ''
|
||||
while len(word) < length:
|
||||
syllable = random.choice(self.syllables)
|
||||
word += syllable
|
||||
return word[:length]
|
||||
|
||||
def generate_unique_words(self, count=10):
|
||||
unique_words = set()
|
||||
while len(unique_words) < count:
|
||||
word = self.generate_word()
|
||||
unique_words.add(word)
|
||||
return list(unique_words)
|
||||
|
||||
if __name__ == '__main__':
|
||||
generator = WordGenerator()
|
||||
words = generator.generate_unique_words(10)
|
||||
print(words)
|
||||
|
Loading…
Reference in New Issue
Block a user