On this page
os.urandom
Prev: os.unlink | Up: os | Next: os.waitid_result
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.urandom
Tags: #public #python3 #stdlib #os
Import
import os
from os import urandom
Signature & Overview
os.urandom(size, /)
Return a bytes object containing random bytes suitable for cryptographic use.
Usage
import os
raw = os.urandom(16)
assert isinstance(raw, bytes) and len(raw) == 16
Gotchas
- OS CSPRNG bytes: Suitable for cryptographic keys and salts; for high-level hex/URL-safe tokens or random choices, prefer the secrets module.
REPL Inspect
from os import urandom
help(urandom)
Linked from
Related notes
- tuts/python3/stdlib_module/os/unlink Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/waitid_result Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/secrets Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib