Skip to content

fix(stdlib): keep math.random state in the VM instead of the host proccess - #442

Open
adriencohen wants to merge 1 commit into
deviceio:mainfrom
adriencohen:fix/math-random-vm-local-state
Open

adriencohen wants to merge 1 commit into
deviceio:mainfrom
adriencohen:fix/math-random-vm-local-state

Conversation

@adriencohen

Copy link
Copy Markdown

A sandboxed script shares the BEAM process with the host that evaluates it, and math.random / math.randomseed ran on that process's global :rand state. Calling math.randomseed(42) reseeded the generator behind the host's own Enum.random/1, Enum.shuffle/1 and :rand calls, so untrusted Lua code could make the host's randomness predictable after an evaluation.

@adriencohen
adriencohen force-pushed the fix/math-random-vm-local-state branch from 4943ea5 to e4e76bb Compare November 27, 2026 05:29
…cess

math.randomseed reseeds the calling process's :rand state, so a script
decides what the host's next Enum.random/1 or Enum.shuffle/1 returns.
@adriencohen
adriencohen force-pushed the fix/math-random-vm-local-state branch from e4e76bb to 44f0132 Compare November 27, 2026 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant