Add RandomStream for independent, thread-friendly random sequences - #198
Merged
Conversation
Random previously drove every call through one shared, non-thread-safe mt19937 engine. RandomStream is an instantiable RNG that owns its own engine, so each subsystem/thread can get an independently seeded, reproducible sequence. Random is now a thin static wrapper around one shared RandomStream, so the distribution logic lives in a single place. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Random's API was previously backed by a single shared, non-thread-safemt19937engine — concurrent calls from multiple threads are a data race.Fling::RandomStream: an instantiable RNG that owns its own engine, so a subsystem, job, or thread can get an independently seeded, reproducible sequence instead of sharing global state.Randomis now a thin static wrapper around one sharedRandomStream(s_Stream), so the distribution logic lives in a single place instead of being duplicated between the two.RandomStream::Init(...)was renamed toRandomStream::Reseed(...)to better describe re-seeding an already-constructed stream.Test plan
python3 scripts/check_comment_style.pycmake --build build --target FlingTests --parallel./build/FlingTests/bin/FlingTests— all 18 test cases pass (13389 assertions), including newRandomStreamcoverage: default construction, seed reproducibility, seed divergence,Reseed, independence between instances, and range checks for all generator methods.🤖 Generated with Claude Code