Pseudo-Random Numbers - Examples
import hashlib, time
startSeed = str(time.time()) + '|'
min = 10
max = 20
for i in range(5):
nextSeed = startSeed + str(i)
hash = hashlib.sha256(nextSeed.encode('ascii')).digest()
bigRand = int.from_bytes(hash, 'big')
rand = min + bigRand % (max - min + 1)
print(nextSeed, bigRand, '-->', rand)1539884529.7564313|0 80821949188459167822103620715837790870744533466506114260335306835341654043374 --> 20
1539884529.7564313|1 74025479792630401388590516952955656999942018130178317853592496371994668720404 --> 12
1539884529.7564313|2 82017697577161203981429946799250236982499988253633196542465974577893633076425 --> 18
1539884529.7564313|3 107386997066995629290834465394867359239275712194747910247567090891223949362198 --> 13
1539884529.7564313|4 83874630241630198317549470506043001102325518306912594861433838548293113930135 --> 10Creating a Secure Random Generator
Last updated