Add Random::fast_bool.

GitOrigin-RevId: 1f7ec3d4a04dcadbdffde18994e7a29f3d22aedc
This commit is contained in:
levlam 2020-10-08 12:47:03 +03:00
parent 6d1d227609
commit 291a9ff43b
2 changed files with 5 additions and 0 deletions

View File

@ -148,6 +148,10 @@ double Random::fast(double min, double max) {
return min + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max - min); return min + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max - min);
} }
bool Random::fast_bool() {
return (fast_uint32() & 1) != 0;
}
Random::Xorshift128plus::Xorshift128plus(uint64 seed) { Random::Xorshift128plus::Xorshift128plus(uint64 seed) {
auto next = [&] { auto next = [&] {
// splitmix64 // splitmix64

View File

@ -35,6 +35,7 @@ class Random {
// distribution is not uniform, min and max are included // distribution is not uniform, min and max are included
static int fast(int min, int max); static int fast(int min, int max);
static double fast(double min, double max); static double fast(double min, double max);
static bool fast_bool();
class Fast { class Fast {
public: public: