// A few common random functions. (1.01)
#include <random>
#include <iostream>
using namespace std;
static thread_local default_random_engine re_(random_device{}());
// Real in the range [0, 1).
double randreal() {
uniform_real_distribution<double> pick(0, 1);
return pick(re_);
}
// Integer in the range [lo, hi].
int randint(int lo, int hi) {
uniform_int_distribution<> pick(lo, hi);
return pick(re_);
}
// Boolean where probability of true is p and false is (1-p).
bool randbool(double p) {
bernoulli_distribution pick(p);
return pick(re_);
}
// Show.
template<typename Func, typename... Args>
void show(int n, Func f, Args... args) {
for (int i = 0; i < n; i++)
cout << f(args...) << ' ';
cout << endl;
}
int main() {
show(10, randreal);
show(10, randint, -5, 5);
show(10, randbool, 0.5);
}
Ly8gQSBmZXcgY29tbW9uIHJhbmRvbSBmdW5jdGlvbnMuICgxLjAxKQoKI2luY2x1ZGUgPHJhbmRvbT4KI2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RhdGljIHRocmVhZF9sb2NhbCBkZWZhdWx0X3JhbmRvbV9lbmdpbmUgcmVfKHJhbmRvbV9kZXZpY2V7fSgpKTsKCi8vIFJlYWwgaW4gdGhlIHJhbmdlIFswLCAxKS4KZG91YmxlIHJhbmRyZWFsKCkgewogICAgdW5pZm9ybV9yZWFsX2Rpc3RyaWJ1dGlvbjxkb3VibGU+IHBpY2soMCwgMSk7CiAgICByZXR1cm4gcGljayhyZV8pOwp9CgovLyBJbnRlZ2VyIGluIHRoZSByYW5nZSBbbG8sIGhpXS4KaW50IHJhbmRpbnQoaW50IGxvLCBpbnQgaGkpIHsKICAgIHVuaWZvcm1faW50X2Rpc3RyaWJ1dGlvbjw+IHBpY2sobG8sIGhpKTsKICAgIHJldHVybiBwaWNrKHJlXyk7Cn0KCi8vIEJvb2xlYW4gd2hlcmUgcHJvYmFiaWxpdHkgb2YgdHJ1ZSBpcyBwIGFuZCBmYWxzZSBpcyAoMS1wKS4KYm9vbCByYW5kYm9vbChkb3VibGUgcCkgewogICAgYmVybm91bGxpX2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