In Linux, using Python 3:
bytes = 32;
raw_random = os.getrandom(bytes)
hex_random = hex(
int.from_bytes(
raw_random, sys.byteorder
))[2:].zfill(2*bytes)
hex_random
Example: 1ded878a7ef3c93389cb08b19a254c846dbd3e88d3b3363dd384977ef81bcc3f
Key is that /dev/urandom
is cryptographically secure except
just after startup.
The getrandom system call
waits until there is enough entropy, compared to reading from /dev/urandom
directly.