random-word icon indicating copy to clipboard operation
random-word copied to clipboard

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

Open byhlel opened this issue 2 years ago • 2 comments

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):

  • OS: Windows
  • Python [3.10]

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.

byhlel avatar Apr 27 '22 22:04 byhlel

@byhlel

def get_random_word() -> str:

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

    return roll()

KonstantinKlepikov avatar Sep 09 '22 22:09 KonstantinKlepikov

@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!

byhlel avatar Sep 10 '22 08:09 byhlel