I basically want to convert a Python object into a fixed length numeric (not alphanumeric) value. One way, I’ve come up with is,
import random
x = Car(brand='toyota', model='corolla', price='10000', year=1997)
random.seed(x)
random.random()
0.13436424411240122
random.seed(x)
random.random()
0.13436424411240122
I’m wondering if there is more convenient and generic way (or library) to make this work?
The way you’re now using is:
Carobject.random.seed()every time.Also, if I were you, I’d like to have a little control on how my number is generated.
The other answers have already showed to you the existence of
hashlib.I would probably use it like this:
Reference on the integer conversion: Convert 32-char md5 string to integer.