jeudi 1 octobre 2020

Python randome with using date and time as seed from 0 to f ( never give 0 or f )

I try get randome value from 0 to f as example my code

import sys, time, random, os
from datetime import datetime
random.seed(datetime.now())

for x in range(1):
    low  = 0x0
    high = 0xf
    randp = str(hex( random.randrange( low, high ) )).lstrip("0x")
    print (randp)

I always get value from 1 to e , but never get 0 or f

i try this

import sys, time, random, os from datetime import datetime random.seed(datetime.now())

for x in range(1):
    low  = 0x000
    high = 0xfff
    randp = str(hex( random.randrange( low, high ) )).lstrip("0x")[1:-1]
    print (randp)

but some times i hv problem ( i get amnty result )

8
>>> 
======================= RESTART: J:/TestRand.py =======================

>>> 
======================= RESTART: J:/TestRand.py =======================
1
>>> 



Aucun commentaire:

Enregistrer un commentaire