// Most common random functions. (1.00)
#include <random>
#include <iostream>
using namespace std;
thread_local default_random_engine s_re(random_device{}());
// Real in the range [0, 1) (exclusive).
double randreal() {
uniform_real_distribution<double> pick(0.0, 1.0);
return pick(s_re);
}
// Integer in the range [lo, hi] (inclusive).
int randint(int lo, int hi) {
uniform_int_distribution<> pick(lo, hi);
return pick(s_re);
}
// Boolean with probability {p true | (1-p) false}.
bool randbool(double p) {
bernoulli_distribution pick(p);
return pick(s_re);
}
// Show.
int main() {
int n = 10;
for (int i = 0; i < n; i++)
cout << randreal() << ' ';
cout << endl;
for (int i = 0; i < n; i++)
cout << randint(-n/2, n/2) << ' ';
cout << endl;
for (int i = 0; i < n; i++)
cout << randbool(0.5) << ' ';
cout << endl;
}
Ly8gTW9zdCBjb21tb24gcmFuZG9tIGZ1bmN0aW9ucy4gKDEuMDApCgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0aHJlYWRfbG9jYWwgZGVmYXVsdF9yYW5kb21fZW5naW5lIHNfcmUocmFuZG9tX2RldmljZXt9KCkpOwoKLy8gUmVhbCBpbiB0aGUgcmFuZ2UgWzAsIDEpIChleGNsdXNpdmUpLgpkb3VibGUgcmFuZHJlYWwoKSB7CiAgICB1bmlmb3JtX3JlYWxfZGlzdHJpYnV0aW9uPGRvdWJsZT4gcGljaygwLjAsIDEuMCk7CiAgICByZXR1cm4gcGljayhzX3JlKTsKfQoKLy8gSW50ZWdlciBpbiB0aGUgcmFuZ2UgW2xvLCBoaV0gKGluY2x1c2l2ZSkuCmludCByYW5kaW50KGludCBsbywgaW50IGhpKSB7CiAgICB1bmlmb3JtX2ludF9kaXN0cmlidXRpb248PiBwaWNrKGxvLCBoaSk7CiAgICByZXR1cm4gcGljayhzX3JlKTsKfQoKLy8gQm9vbGVhbiB3aXRoIHByb2JhYmlsaXR5IHtwIHRydWUgfCAoMS1wKSBmYWxzZX0uCmJvb2wg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