-
Notifications
You must be signed in to change notification settings - Fork 1
feat: rewrite random.cpp #44
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,8 @@ | ||
| #include "../common/common.hpp" | ||
|
|
||
| // what: tiny RNG wrapper with fixed default seed for reproducible tests/shuffles. | ||
| // time: O(1) per call; memory: O(1) | ||
| // constraint: uses mt19937_64. | ||
| // usage: rng rd(2); ll x = rd.ll_range(l, r); rd.shuf(v); | ||
| struct rng { | ||
| static constexpr ull DEFAULT_SEED = 712367; | ||
| mt19937_64 eng; | ||
|
|
||
| rng(ull seed = DEFAULT_SEED) : eng(seed) {} | ||
|
|
||
| ll ll_range(ll l, ll r) { | ||
| // edge: l <= r | ||
| uniform_int_distribution<ll> dis(l, r); | ||
| return dis(eng); | ||
| } | ||
|
|
||
| int int_range(int l, int r) { | ||
| uniform_int_distribution<int> dis(l, r); | ||
| return dis(eng); | ||
| } | ||
|
|
||
| template <class T> | ||
| void shuf(vector<T> &v) { | ||
| shuffle(all(v), eng); | ||
| } | ||
| }; | ||
| // what: mt19937_64 quick usage snippet (time-seeded + rand range + shuffle). | ||
| // time: O(1) per draw; memory: O(1) | ||
| // constraint: uniform_int_distribution is inclusive [l, r]. | ||
| // constraint: chrono seed isn't cryptographically secure. | ||
| // usage: mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); | ||
| // usage: ll x = uniform_int_distribution<ll>(l, r)(rng); shuffle(all(v), rng); | ||
This file was deleted.
Oops, something went wrong.
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.
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.
This file now contains only comments and no implementation, so including
src/8-misc/random.cppno longer defines the previously availablernghelper. Any existing templates that relied onrng(as provided before this commit) will now fail to compile after updating, which is a breaking change for the library. If the intent is to keep a quick RNG utility, the module needs to still export a minimal wrapper or type alias instead of being comment-only.Useful? React with 👍 / 👎.