-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set-random-seed added #848
Merged
Merged
Conversation
This file contains 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
vsbogd
requested changes
Feb 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test which checks that set-random-seed
leads to deterministic results. Also I would add a code proposed by @Necr0x0Der if you have one.
vsbogd
reviewed
Feb 10, 2025
vsbogd
previously approved these changes
Feb 10, 2025
Necr0x0Der
previously approved these changes
Feb 10, 2025
Return sudden remove
…ntal into random_seed
This makes code simpler and isolates internal API from rand library internals.
Wrap StdRng into RandomGenerator grounded atom
vsbogd
approved these changes
Feb 18, 2025
Necr0x0Der
approved these changes
Feb 19, 2025
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.
So, I've figured out how to properly use thread_local for creating thread_local global variable in Rust. Usage ofrandom-int
andrandom-float
is the same.Base seed is coming fromStdRng::from_os_rng()
. Newset-random-seed
is used to set a random seed.So when this operation is called,GLOBAL_RNG
(which is thread local) will be reinitialized with a new seed.I'm not sure what kind of tests should I provide forset-random-seed
operation so I've created kinda simple one.Example is quite simple:!(random-int 0 5) # just a regular call without pre-defined seed as before!(set-random-seed! 5) # setting a seed to a random generator
!(random-int 0 5) # now calling random-int after reinitializing generator with a seed.
Update. It was decided to refactor API and add some additional functions like
new-random-generator
etc. So API is know looks like this:new-random-generator
creates random generator instance for further usage. Takes seed as an argument;random-int\random-float
now takes not only range but also instance of random generator;StdRng::from_os_rng();
which called&rng
and which can be used just like user-creeated random generator instance;set-random-seed
accepts number and random generator instance and changes its behavior using random seed;reset-random-generator
discards all changes to random generator instance and reinitialize it usingStdRng::from_os_rng();
.Example of usage