I'm trying to generate a unique seed every time the script runs based on a random int value. However, the script gets caught up and keeps one of the int values after sometimes causing it to get stuck in memory. Anyone have any ideas?
import random
import hashlib
def generateSeed():
# Select Random Number from 0-1000
randomnum = random.randint(0,1000)
#print (randomnum)
print ('RANDOM SEED NUMBER is ' + str(randomnum))
# Use Random Int to Generate a Seed
seed = random.seed(randomnum)
#Generate A Number based on the seed
number = random.random()
print ('The random nubmer generated based on the seed is : ' + str(number))
# Hash the number generated
lib = hashlib.sha256()
lib.update(str(number).encode('utf-8'))
x = lib.hexdigest()
print ('The SHA256 Hash is : ' + x)
# Splice the Hash
newx = x[:8]
print ('The Spliced Hash is : '+ newx)
# Convert the spliced hash to decimal
decimal = int(newx, 16)
print ('The Hex to decimal is : ' + str(decimal))
# Modulo the decimal
print (decimal % 15)
for test in range(0, 500):
generateSeed()
test = test + 1
#random.seed(466)
#print(random.random())
Would be much appreciated, I'm just trying to create a provably fair generator based on the random ints.
Aucun commentaire:
Enregistrer un commentaire