-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hardening suggestions for probabilityguesser-tk / test #4
base: test
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import numpy | ||
import matplotlib.pyplot as plot | ||
from tkinter import * | ||
import random | ||
import secrets | ||
|
||
#hi! | ||
|
||
|
@@ -17,29 +17,29 @@ def click(): | |
output.insert(END, calculateScore(guess, probability)) | ||
|
||
def coinToss(): | ||
rng = random.randint(1, 20) | ||
rng = secrets.SystemRandom().randint(1, 20) | ||
if (rng % 4 == 0): | ||
fair = True | ||
else: | ||
fair = False | ||
if not fair: | ||
rng = random.randint(1, 20) | ||
rng = secrets.SystemRandom().randint(1, 20) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace random.{func} with more secure secrets library functions. |
||
if (rng % 2 == 0): | ||
range_lower = True | ||
else: | ||
range_lower = False | ||
if not range_lower: | ||
probability = random.randint(60, 80) | ||
probability = secrets.SystemRandom().randint(60, 80) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace random.{func} with more secure secrets library functions. |
||
else: | ||
probability = random.randint(20, 40) | ||
probability = secrets.SystemRandom().randint(20, 40) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace random.{func} with more secure secrets library functions. |
||
else: | ||
probability = 50 | ||
|
||
heads_dist = numpy.array(0) | ||
heads = 0 | ||
for i in range(1,1000): | ||
for j in range(1,30): | ||
comparison = random.randint(1, 100) | ||
comparison = secrets.SystemRandom().randint(1, 100) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace random.{func} with more secure secrets library functions. |
||
if comparison <= probability: | ||
heads += 1 | ||
heads_dist = numpy.insert(heads_dist, 0, heads) | ||
|
@@ -52,7 +52,7 @@ def coinToss(): | |
|
||
|
||
#seed rng | ||
random.seed() | ||
secrets.SystemRandom().seed() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace random.{func} with more secure secrets library functions. |
||
#configure window | ||
window = Tk() | ||
window.title("Coin toss guessing game") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace random.{func} with more secure secrets library functions.