Skip to content

Add RandomStream for independent, thread-friendly random sequences - #198

Merged
BenjaFriend merged 3 commits into
mainfrom
random-improvements
Aug 29, 2026
Merged

Add RandomStream for independent, thread-friendly random sequences#198
BenjaFriend merged 3 commits into
mainfrom
random-improvements

Conversation

@BenjaFriend

Copy link
Copy Markdown
Member

Summary

  • Random's API was previously backed by a single shared, non-thread-safe mt19937 engine — concurrent calls from multiple threads are a data race.
  • Adds 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.
  • Random is now a thin static wrapper around one shared RandomStream (s_Stream), so the distribution logic lives in a single place instead of being duplicated between the two.
  • RandomStream::Init(...) was renamed to RandomStream::Reseed(...) to better describe re-seeding an already-constructed stream.

Test plan

  • python3 scripts/check_comment_style.py
  • cmake --build build --target FlingTests --parallel
  • ./build/FlingTests/bin/FlingTests — all 18 test cases pass (13389 assertions), including new RandomStream coverage: default construction, seed reproducibility, seed divergence, Reseed, independence between instances, and range checks for all generator methods.

🤖 Generated with Claude Code

BenjaFriend and others added 3 commits August 28, 2026 19:46
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>
@BenjaFriend
BenjaFriend merged commit 6d46f67 into main Aug 29, 2026
6 checks passed
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