vaibhavsingh97 / random-word

This is a simple python package to generate random english words
https://pypi.org/project/random-word/
MIT License
123 stars 25 forks source link

Function .get_random_word returns None too often (% depends of parameters) #79

Open byhlel opened 2 years ago

byhlel commented 2 years ago

The get_random_word function returns None to often When called with various parameters, it returns None rather than a word...

To Reproduce Here is the code to test on your own:

from random_word import RandomWords
r=RandomWords()
for i in range (100):
    word=r.get_random_word(hasDictionaryDef="true")
    print(word)

Expected behavior I would have expected for a word to be returned for each case, it becomes enev more obvious when you add a maxLength (in my case but probably with other parameters too)

Screenshots This is a screenshot with following parameters:

hasDictionaryDef="true"
maxLength=10

words_lenght10_dicdef

Environment (please complete the following information):

Additional Informations Do not hesitate to comment for any additionnal informations towards my issue!

Greetings Thank you for taking time to read and I hope we will be able to fix this issue! Bilal.

KonstantinKlepikov commented 2 years ago

@byhlel

def get_random_word() -> str:

    def roll():
        result = rw.get_random_word()
        if not result:
            result = roll()
        return result

    return roll()
byhlel commented 2 years ago

@byhlel

def get_random_word() -> str:

    def roll():
        result = rw.get_random_word()
        if not result:
            result = roll()
        return result

    return roll()

This seems indeed to be a good workaround, but it was to mainly point out the issue to the package owners. Thank you very much though!