code wiki / (root) / nx_rand.nx

nx_rand.nx

buildroot/runtime/nx_rand.nx

3802 B105 linesdepth 2pulls 2 transitivereach 635 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

rand.nx -- cryptographically secure random bytes via /dev/urandom. Phase G5 in the roadmap. Opens /dev/urandom once, reads on demand. Used for session tokens, CSRF, post IDs, crypto nonces. Not suitable for massive random streams (~200 MB/s ceiling); good enough for the compiler + server use cases. Lifecycle: first call to rand_bytes() or rand_u64() lazily opens /dev/urandom and caches the fd in a heap-stored i64. Subsequent calls reuse the same fd. Two primary entry points: rand_bytes(out, n) -- fill `n` bytes into `out`; returns bytes read rand_u64() -- return a single 64-bit value

dependencies 1 imports · 11 importers

nx_syscalls.nx nx_rand.nx nx_csrf_token.nx nx_dp.nx nx_nanoid.nx nx_oauth2_pkce.nx nx_obs.nx nx_rand_gate.nx nx_session_id.nx nx_ulid.nx nx_uuid_v1.nx nx_websocket_client_upgrade.nx

diagram shows first 10 each side; +0 more imports, +1 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_csrf_token.nxnx_dp.nxnx_nanoid.nxnx_oauth2_pkce.nxnx_obs.nxnx_rand_gate.nxnx_session_id.nxnx_ulid.nxnx_uuid_v1.nxnx_websocket_client_upgrade.nxnx_x25519_ephemeral.nx

structs

none

consts

23const K_MAGIC_9223372036854775807: i64 = 9223372036854775807

functions

29func rand_fd_slot() -> *i64
calls 1: sys_mmap
48func rand_open_urandom() -> i64
called by 1: rand_bytes calls 1: sys_openat_rd
55func rand_bytes(out: *u8, n: i64) -> i64
75func rand_u64() -> i64
called by 2: rand_belowmain calls 2: sys_mmaprand_bytes
84func rand_below(bound: i64) -> i64
called by 1: main calls 1: rand_u64