dimanche 9 mai 2021

Occasional error with Python's random.randint() function

I'm working on a program to generate characters and worlds for an RPG-type game. I'm using the randint() function of the random module, but I (very occasionally, maybe once every twenty or more times) receive this error.

    Traceback (most recent call last):
      File "src/main.py", line 1, in <module>
        from rpg import character, world
      File "/home/runner/tool-jam/src/rpg/world.py", line 99, in <module>
        generate_settlement()
      File "/home/runner/tool-jam/src/rpg/world.py", line 43, in generate_settlement
        races, diversity = generate_racial_diversity()
      File "/home/runner/tool-jam/src/rpg/world.py", line 86, in generate_racial_diversity
        racial_diversity = random.randint(1, total_percentage)
      File "/usr/lib/python3.8/random.py", line 248, in randint
        return self.randrange(a, b+1)
      File "/usr/lib/python3.8/random.py", line 226, in randrange
        raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
    ValueError: empty range for randrange() (1, 1, 0)

Here's my code: GitHub Link




Aucun commentaire:

Enregistrer un commentaire