From f904ef2e2f3b40efebd0e74e205b758ceb9b15ce Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Sat, 5 Nov 2016 20:40:11 -0400 Subject: [PATCH] Fix the number generator The number generator disproportionately favors digits 1-5 over 6. This fixes it using random's randint() function and the SystemRandom class. Function numgen() will now always return a list. --- README.md | 8 +++++--- dicekey/diceware.py | 14 +++++--------- setup.py | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b9248be..c62d86e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ To uninstall Dicekey: `sudo dpkg -r dicekey` ## Development -Dicekey is developed on Trisquel GNU/Linux 6.0.1 TLS i686 with Python 2.7.3 +Dicekey is developed on Trisquel GNU/Linux 7 x86_64 with Python 2.7.6 and checkinstall 1.6.2. There *are* plans to support other platforms. Development follows the the [Semantic @@ -27,7 +27,8 @@ occur but we shall try to follow these guidelines to the best of our ability. ## Copyrights and Licenses Copyright (C) 2016 Kris Lamoureux -> All Dicekey + +All Dicekey code is [Free Software](https://www.gnu.org/philosophy/free-sw.en.html) released under the [GNU General Public License](https://github.com/Kris619/Dicekey/blob/master/LICENSE) as published @@ -35,6 +36,7 @@ by the Free Software Foundation, version 3 of the License. Copyright (C) 2001 Arnold G. Reinhold, Cambridge, Massachusetts USA. -> A G Reinhold licenses its rights to the English Diceware Wordlist under the + +A G Reinhold licenses its rights to the English Diceware Wordlist under the [Creative Commons CC-BY 3.0](https://creativecommons.org/licenses/by/3.0/) license. diff --git a/dicekey/diceware.py b/dicekey/diceware.py index 667a979..13c3011 100644 --- a/dicekey/diceware.py +++ b/dicekey/diceware.py @@ -14,7 +14,7 @@ # along with this program. If not, see . # Built-in -import os +import random # Generate Diceware numbers @@ -25,14 +25,10 @@ def numgen(length=1): number = "" for _ in range(5): - bytedata = os.urandom(1) - intdata = int(bytedata.encode("hex"), 16) - result = intdata * 5 / 255 + 1 - number = number + str(result) + PRNG = random.SystemRandom() + digit = PRNG.randint(1, 6) + number = number + str(digit) numlist.append(number) - if len(numlist) == 1: - return numlist[0] - else: - return numlist + return numlist diff --git a/setup.py b/setup.py index 14b1964..b496b7c 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ from distutils.core import setup NAME = "Dicekey" -VERSION = "0.2.0-prealpha" +VERSION = "1.2.0-prealpha" AUTHOR = "Kris Lamoureux" AUTHOR_EMAIL = "KrisPublicEmail@gmail.com" URL = "https://github.com/Kris619/Dicekey/"