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
579524cb
Commit
579524cb
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Add doc strings.
parent
dc59bc87
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
diceware/random_sources.py
+7
-0
7 additions, 0 deletions
diceware/random_sources.py
with
7 additions
and
0 deletions
diceware/random_sources.py
+
7
−
0
View file @
579524cb
...
...
@@ -128,6 +128,11 @@ class RealDiceRandomSource(object):
self
.
dice_sides
=
6
def
pre_check
(
self
,
num_rolls
,
sequence
):
"""
Checks performed before picking an item of a sequence.
We make sure that `num_rolls`, the number of rolls, is in an
acceptable range and issue an hint about the procedure.
"""
if
num_rolls
<
1
:
raise
ValueError
(
"
Must provide at least %s items
"
%
self
.
dice_sides
)
...
...
@@ -139,6 +144,8 @@ class RealDiceRandomSource(object):
return
def
choice
(
self
,
sequence
):
"""
Pick one item out of `sequence`.
"""
num_rolls
=
int
(
math
.
log
(
len
(
sequence
),
self
.
dice_sides
))
self
.
pre_check
(
num_rolls
,
sequence
)
result
=
0
...
...
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