diff --git a/diceware/random_sources.py b/diceware/random_sources.py index b6293b0acae41b951905b49559763726ad59cfc5..a14e12386b2db3690ef8ad259d644a3548923d69 100644 --- a/diceware/random_sources.py +++ b/diceware/random_sources.py @@ -68,6 +68,7 @@ and the random source defined in the given class would be used for generating a passphrase. """ +import math import sys from random import SystemRandom @@ -125,7 +126,16 @@ class RealDiceRandomSource(object): def __init__(self, options): self.options = options - def get_input(self): - """Just a temporary helper to see, whether input mocks in tests work. - """ - return input_func("Enter some values: ") + def choice(self, sequence): + num_rolls = int(math.log(len(sequence), 6)) + print( + "You have to roll %s dice (or a single dice %s times)." % ( + num_rolls, num_rolls)) + result = 0 + for i in range(num_rolls): + rolled = None + while rolled not in ["1", "2", "3", "4", "5", "6"]: + rolled = input_func( + "Please number shows dice number %s? " % (i + 1)) + result += ((6 ** i) * int(rolled) - 1) + return sequence[result]