Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
diceware-debian
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drebs
diceware-debian
Commits
1c47f45a
Commit
1c47f45a
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
First simple choice() method.
parent
acb25f65
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
diceware/random_sources.py
+14
-4
14 additions, 4 deletions
diceware/random_sources.py
with
14 additions
and
4 deletions
diceware/random_sources.py
+
14
−
4
View file @
1c47f45a
...
...
@@ -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
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment