-
Notifications
You must be signed in to change notification settings - Fork 118
Add deterministic random class #1255
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
base: main
Are you sure you want to change the base?
Add deterministic random class #1255
Conversation
| import org.apiguardian.api.API; | ||
| import org.apiguardian.api.API.Status; | ||
|
|
||
| @API(since = "1.1.16", status = Status.MAINTAINED) |
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.
It should be EXPERIMENTAL
| this.currentSeed = value; | ||
|
|
||
| if (!SEED_CACHE.containsKey(value)) { | ||
| manageCacheSize(); |
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.
I don't think it's necessary to extract the method; it would be better to inline it.
| import org.apiguardian.api.API.Status; | ||
|
|
||
| @API(since = "1.1.16", status = Status.MAINTAINED) | ||
| public class DeterministicRandom extends Random { |
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.
I think it would be better to create a new interface for obtaining the Random instance and the seed value.
It is to avoid using the DeterministicRandom directly.
Summary
Implement DeterministicRandom class with seed-based Random instance caching for deterministic test reproducibility.
Description
DeterministicRandomclass that extendsRandomnextLong()generated values as keysgetRandomInstance(long seed)to retrieve cached Random instances by seedgetCurrentSeedRandom()to get the Random instance for the current seedHow Has This Been Tested?
./gradlew :fixture-monkey-api:testpasses successfullynextLong(), instance retrieval, cache size limit (≤32), deterministic behavior, and seed independenceIs the Document updated?
Not yet.