From 240ea799e9d14e3b0460bfbae258444b2c459e47 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 05:33:58 +0000 Subject: [PATCH] Secure Source of Randomness --- main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index fdd0e7d..a0a14bf 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import numpy import matplotlib.pyplot as plot from tkinter import * -import random +import secrets #hi! @@ -17,21 +17,21 @@ 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) 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) else: - probability = random.randint(20, 40) + probability = secrets.SystemRandom().randint(20, 40) else: probability = 50 @@ -39,7 +39,7 @@ def coinToss(): 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) 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() #configure window window = Tk() window.title("Coin toss guessing game")