Created
November 18, 2022 20:14
-
-
Save reywood/f2c176e4ab0565f7a25ccc0c1b8c0f39 to your computer and use it in GitHub Desktop.
Generate a random 64 bit integer in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from uuid import uuid4 | |
_8_bit_mask = 0b11111111 | |
_24_bit_mask = 0b11111111_11111111_11111111 | |
def generate_random_64_bit_number(): | |
u = uuid4() | |
return ( | |
((u.node & _24_bit_mask) << 40) | |
+ ((u.clock_seq_hi_variant & _8_bit_mask) << 32) | |
+ ((u.clock_seq_low & _8_bit_mask) << 24) | |
+ ((u.time_hi_version & _8_bit_mask) << 16) | |
+ ((u.time_mid & _8_bit_mask) << 8) | |
+ u.time_low | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment