UUIDv4
I was in need of using a quick UUIDv4 to use as a token but I had no internet, so I had to write a short one
import secrets
def uuidv4():
r = secrets.randbits
return ''.join(
f"{r(4):x}" if c=='x' else f"{((r(4)&3)|8):x}" if c=='y' else c
for c in 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
)
really simple and small. And it works!