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.
This commit is contained in:
Kris Lamoureux 2016-11-05 20:40:11 -04:00
parent 50e75be7e8
commit f904ef2e2f
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
3 changed files with 11 additions and 13 deletions

View File

@ -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.

View File

@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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

View File

@ -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/"