I am working with Python in an API. The API is coded using Javascript, and I do not know how would be the equivalent code of this line in Python:
JavaScript
x
2
1
crypto.randomBytes(8).join("")
2
I found out this link https://docs.python.org/3/library/uuid.html, but I do not know what to do to get exactly the same result.
Thank you for your help
Advertisement
Answer
Try:
JavaScript
1
3
1
from random import randint
2
bytes([randint(0, 255) for _ in range(8)])
3
EDIT: If you need secure random bytes:
JavaScript
1
3
1
from secrets import token_bytes
2
token_bytes(8)
3