The following is the code in 1.80 for UUID generation from gluon/utils.py.
Can someone explain to me what is going on here? What's with all the
bitshifting?
web2py_uuid_locker = thread.allocate_lock()
node_id = uuid.getnode()
milliseconds = int(time.time() * 1e3)
def rotate(i):
a = random.randrange(256)
b = (node_id >> 4*i) % 256
c = (milliseconds >> 4*i) % 256
return (a + b + c) % 256
def web2py_uuid():
web2py_uuid_locker.acquire()
try:
bytes = [chr(rotate(i)) for i in range(16)]
return str(uuid.UUID(bytes=bytes, version=4))
finally:
web2py_uuid_locker.release()
--
Craig Younkins