Skip to content
Snippets Groups Projects
Commit 8f723b6b authored by ulif's avatar ulif
Browse files

Always check for one-item sequences.

With one item in sequence we do not have to roll dice. This holds for
all sorts of dice.
parent 2a957818
No related branches found
No related tags found
No related merge requests found
......@@ -148,12 +148,12 @@ class RealDiceRandomSource(object):
def choice(self, sequence):
"""Pick one item out of `sequence`.
"""
if len(sequence) == 1:
return sequence[0] # no need to roll dice.
num_rolls = int(math.log(len(sequence), self.dice_sides))
if num_rolls < 1:
# If this happens, there are less values in the sequence to
# choose from than there are dice sides.
if len(sequence) == 1:
return sequence[0]
# Check whether len(sequence) is a factor of dice.sides
if self.dice_sides % len(sequence) == 0:
num_rolls = 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment