vendredi 24 février 2023

How to fix this problem when generating a pseudorandom number in Python?

import hashlib
import time
def random():
    hashtime = str(int(time.time() * (10 ** 6)))
    encoded = hashlib.new("sha3_512", hashtime.encode())
    decoded = int(encoded.hexdigest(), 16)
    
    dcsmall = decoded / (10 ** (len(str(decoded))))
    return (dcsmall)

I tried this code to simulate the function random.random() without the module random. I wanted to generate a random number between 0 and 1 but this code doesn't output numbers between 0 and 0.1 because of the length of "decoded" and I have no idea how to fix it. Please don't make huge changes to my code but instead give me an idea how to solve the problem. Thank you




Aucun commentaire:

Enregistrer un commentaire