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
d42c2a0e
Commit
d42c2a0e
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Do working version of choice().
The new real dice random source now works on a very plain level.
parent
f802c1aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diceware/random_sources.py
+4
-4
4 additions, 4 deletions
diceware/random_sources.py
tests/test_random_sources.py
+4
-2
4 additions, 2 deletions
tests/test_random_sources.py
with
8 additions
and
6 deletions
diceware/random_sources.py
+
4
−
4
View file @
d42c2a0e
...
...
@@ -133,13 +133,13 @@ class RealDiceRandomSource(object):
if
6
**
num_rolls
<
len
(
sequence
):
print
(
"
Warning: entropy is reduced!
"
)
print
(
"
You have to
roll %s dice (or a single dice %s times).
"
%
(
"
Please
roll %s dice (or a single dice %s times).
"
%
(
num_rolls
,
num_rolls
))
result
=
0
for
i
in
range
(
num_rolls
):
for
i
in
range
(
num_rolls
,
0
,
-
1
):
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
)
"
What
number shows dice number %s?
"
%
(
num_rolls
-
i
+
1
))
result
+=
((
6
**
(
i
-
1
)
)
*
(
int
(
rolled
)
-
1
)
)
return
sequence
[
result
]
This diff is collapsed.
Click to expand it.
tests/test_random_sources.py
+
4
−
2
View file @
d42c2a0e
...
...
@@ -174,7 +174,7 @@ class TestRealDiceRandomSource(object):
self
.
fake_input_values
([
"
1
"
,
"
2
"
],
monkeypatch
)
src
=
RealDiceRandomSource
(
None
)
sequence
=
list
(
range
(
6
**
2
))
expected_index
=
1
*
2
-
1
# = roll_1
x
roll_2 - 1
expected_index
=
6
*
(
1
-
1
)
+
(
2
-
1
)
# =
6 x
roll_1
+
roll_2 - 1
assert
src
.
choice
(
sequence
)
==
sequence
[
expected_index
]
def
test_choice_num_of_dice_for_seq_len216
(
self
,
monkeypatch
):
...
...
@@ -182,7 +182,9 @@ class TestRealDiceRandomSource(object):
self
.
fake_input_values
([
"
1
"
,
"
2
"
,
"
3
"
],
monkeypatch
)
src
=
RealDiceRandomSource
(
None
)
sequence
=
list
(
range
(
6
**
3
))
# 216
expected_index
=
1
*
2
*
3
-
1
# = roll_1 x roll_2 x roll_3 - 1
expected_index
=
0
+
6
+
3
-
1
# = 6^2 x (roll_1 - 1)
# + 6^1 x (roll_2 - 1)
# + roll_3 - 1
assert
src
.
choice
(
sequence
)
==
sequence
[
expected_index
]
def
test_hint_if_entropy_is_decreased
(
self
,
monkeypatch
,
capsys
):
...
...
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