Leonetienne/Eule
Homemade math library, mainly targetted towards computer graphics
|
Go to the documentation of this file.
8 #define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng();
13 std::random_device randomSource;
16 std::array<int, std::mt19937::state_size> seedValues;
17 std::generate_n(seedValues.data(), seedValues.size(), std::ref(randomSource));
18 std::seed_seq seedSequence(seedValues.begin(), seedValues.end());
21 rng = std::mt19937(seedSequence);
23 isRngInitialized =
true;
33 return (rng() % 694206942069ll) / 694206942069.0;
58 return (
Random() * (max - min)) + min;
65 return (rng() % (max + 1 - min)) + min;
68 double Math::Oscillate(
const double a,
const double b,
const double counter,
const double speed)
70 return (sin(counter * speed *
PI -
HALF_PI) * 0.5 + 0.5) * (b-a) + a;
78 std::mt19937 Math::rng;
79 bool Math::isRngInitialized =
true;
#define MAKE_SURE_RNG_IS_INITIALIZED
static bool RandomChance(const double chance)
Will 'roll' a dice, returning true percent of the time.
static constexpr double PI
Pi up to 50 decimal places.
static double RandomRange(const double min, const double max)
Will return a random double within a range These bounds are INCLUSIVE!
static unsigned int RandomInt()
Will return a random integer.
static int RandomIntRange(const int max, const int min)
Will return a random integer within a range.
static double Random()
Will return a random double between 0 and 1
static unsigned int RandomUint()
Will return a random unsigned integer.
static constexpr double HALF_PI
Pi divided by two.
static double Oscillate(const double a, const double b, const double counter, const double speed)
Kind of like , but it oscillates over instead of , by a given speed.