nx_rand.nx
buildroot/runtime/nx_rand.nx
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
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
| 23 | const K_MAGIC_9223372036854775807: i64 = 9223372036854775807 |
functions
| 29 | func rand_fd_slot() -> *i64 calls 1: sys_mmap |
| 48 | func rand_open_urandom() -> i64 |
| 55 | func rand_bytes(out: *u8, n: i64) -> i64 |
| 75 | func rand_u64() -> i64 |
| 84 | func rand_below(bound: i64) -> i64 |