code wiki / (root) / nx_prng.nx

nx_prng.nx

buildroot/runtime/nx_prng.nx

3546 B108 linesdepth 2pulls 2 transitivereach 114 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_prng.nx -- deterministic pseudo-random number generator. Park-Miller minimal-standard LCG (Lewis-Goodman-Miller 1969, "Minimal Standard" by Park-Miller 1988): state_{n+1} = (state_n * 48271) mod (2^31 - 1) Period 2^31 - 2. Passes basic statistical tests; sufficient for non-cryptographic randomization (Monte Carlo, sampling, simulation, stochastic algorithms, init for k-means, etc.). NEVER use for cryptography or security-sensitive randomness. Pure i64. Deterministic given seed; identical state -> identical output forever, which is what you want for reproducible tests. genealogy_id: park_miller_1988_minimal_standard + lewis_1969_lcg lineage_id: linear_congruential_generator

dependencies 1 imports · 38 importers

nx_syscalls.nx nx_prng.nx _ttt_test_trace.nx nx_actor_role_game_logic.nx nx_actor_role_llm.nx nx_actor_role_llm_v2_real_test.nx nx_batched_gate.nx nx_checkers.nx nx_checkers_render.nx nx_director_pipeline.nx nx_director_pipeline_test.nx nx_f32_llm_serve.nx

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

imports: nx_syscalls.nx

imported by: _ttt_test_trace.nxnx_actor_role_game_logic.nxnx_actor_role_llm.nxnx_actor_role_llm_v2_real_test.nxnx_batched_gate.nxnx_checkers.nxnx_checkers_render.nxnx_director_pipeline.nxnx_director_pipeline_test.nxnx_f32_llm_serve.nxnx_f32_sampler.nxnx_f32_sampler_test.nxnx_gguf_fixture_tiny.nxnx_llm_batch_serve.nxnx_llm_run.nxnx_llm_run_v2.nxnx_llm_run_v2_test.nxnx_llm_sched.nxnx_llm_sched_gate.nxnx_moment_resolve.nxnx_moment_resolve_test.nxnx_monte_carlo.nxnx_numeric_oracle.nxnx_numeric_oracle_test.nxnx_paged_fwd_gate.nxnx_poisson_disk.nxnx_prng_test.nxnx_procgen_features.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning.nxnx_reasoning_gate.nxnx_reasoning_paged.nxnx_specdec_gate.nxnx_tictactoe.nxnx_tictactoe_test.nxnx_token_sample.nxnx_user_sim_games.nx

structs

none

consts

25const NX_MAGIC_16384: i64 = 16384
27const NX_PRNG_M: i64 = 2147483647 // 2^31 - 1 Mersenne prime
28const NX_PRNG_A: i64 = 48271 // proven good multiplier

functions

35func nx_prng_init(state: *i64, seed: i64) -> i64
50func nx_prng_next(state: *i64) -> i64
58func nx_prng_range(state: *i64, n: i64) -> i64
64func nx_prng_range_lo_hi(state: *i64, lo: i64, hi: i64) -> i64
73func nx_prng_q14(state: *i64) -> i64
calls 1: nx_prng_next
78func nx_prng_uniform_q14(state: *i64) -> i64
86func nx_prng_bernoulli(state: *i64, p_q14: i64) -> i64
called by 1: main calls 1: nx_prng_uniform_q14
97func nx_prng_shuffle(state: *i64, arr: *i64, n: i64) -> i64
called by 1: main calls 1: nx_prng_range