uuid.UUID(bytes=x.bytes) form where bytes are passed in by r

Re: uuid.UUID(bytes=x.bytes) form where bytes are passed in

Code:
x=ramdom.randint(1,10000)
uuid.UUID(bytes=x.bytes)
Getting this kind of error:
Code:
AttributeError: 'int' object has no attribute 'bytes'
 
Re: uuid.UUID(bytes=x.bytes) form where bytes are passed in

Code:
import sys, random, uuid
uuid.UUID(bytes = "%016x" % (random.randint(0, sys.maxint)))
 
Re: uuid.UUID(bytes=x.bytes) form where bytes are passed in

Code:
import sys, random, uuid
uuid.UUID(bytes = "%016x" % (random.randint(0, sys.maxint)))
Is this meets requirement of 128 bits. Also how do I need to test whether this meets 128bits??
 
Re: uuid.UUID(bytes=x.bytes) form where bytes are passed in

RTM: Python Documentation: 9.6. random — Generate pseudo-random numbers.

... Almost all module functions depend on the basic function random(), which generates a random float uniformly in the semi-open range [0.0, 1.0). Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. ...

So the randomness of the calls to the random object is at best 53 bits. If this does not meet your requirements, then use os.urandom().

Code:
import os, uuid
uuid.UUID(bytes = os.urandom(16))

However, you still need to explain to yourself why you choose random.randint(1,10000) in the first place.
 
Re: uuid.UUID(bytes=x.bytes) form where bytes are passed in

Thanks a lot @obsigna... I'm very new to Python also these kind of issues.
 
Last edited by a moderator:
Back
Top