Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions src/8-misc/random.cpp
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].
Comment on lines +3 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep a usable RNG helper in random.cpp

This file now contains only comments and no implementation, so including src/8-misc/random.cpp no longer defines the previously available rng helper. Any existing templates that relied on rng (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 👍 / 👎.

// 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);
30 changes: 0 additions & 30 deletions tests/8-misc/test_random.cpp

This file was deleted.