From 291a9ff43b495129fa0c783b59756dfb509aa11f Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 8 Oct 2020 12:47:03 +0300 Subject: [PATCH] Add Random::fast_bool. GitOrigin-RevId: 1f7ec3d4a04dcadbdffde18994e7a29f3d22aedc --- tdutils/td/utils/Random.cpp | 4 ++++ tdutils/td/utils/Random.h | 1 + 2 files changed, 5 insertions(+) diff --git a/tdutils/td/utils/Random.cpp b/tdutils/td/utils/Random.cpp index 1cda18e65..76b22603c 100644 --- a/tdutils/td/utils/Random.cpp +++ b/tdutils/td/utils/Random.cpp @@ -148,6 +148,10 @@ double Random::fast(double min, double max) { return min + fast_uint32() * 1.0 / std::numeric_limits::max() * (max - min); } +bool Random::fast_bool() { + return (fast_uint32() & 1) != 0; +} + Random::Xorshift128plus::Xorshift128plus(uint64 seed) { auto next = [&] { // splitmix64 diff --git a/tdutils/td/utils/Random.h b/tdutils/td/utils/Random.h index 41a7d60e6..a79fbb0f1 100644 --- a/tdutils/td/utils/Random.h +++ b/tdutils/td/utils/Random.h @@ -35,6 +35,7 @@ class Random { // distribution is not uniform, min and max are included static int fast(int min, int max); static double fast(double min, double max); + static bool fast_bool(); class Fast { public: