function [r, state] = maraca_rng(state, n) % MARACA_RNG Portable seeded uniform generator (32-bit LCG). % Returns n uniforms in (0, 1) as a column vector, plus the advanced state. % Deliberately not MATLAB's rand: the same seed must produce the identical % impact process in the numbl CLI, Node, and the browser, and every double % here stays below 2^53 so the arithmetic is exact everywhere. r = zeros(n, 1); for i = 1:n state = mod(state * 1664525 + 1013904223, 4294967296); r(i) = (state + 0.5) / 4294967296; end end