Skip to Content
oxcrypto

Operating system CSPRNG

Read random bytes from the operating system.

from oxcrypto import random

key = random.bytes(32)

random.bytes(n) reads n bytes from the operating system CSPRNG through the getrandom 0.4 crate, for example getrandom(2) on Linux and BCryptGenRandom on Windows. The GIL is released while it reads. A failing system source raises OSError.

oxcrypto does not provide random integers: use secrets.randbelow, which also reads the operating system CSPRNG.