From 46fde902cf1b699d056a3e8919c762f4e295ede0 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 20 Jan 2024 01:31:16 +0100 Subject: [PATCH] Use c++ 11 random --- src/Vec2d/Vec2d.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Vec2d/Vec2d.h b/src/Vec2d/Vec2d.h index 8fcabc6..331dab9 100644 --- a/src/Vec2d/Vec2d.h +++ b/src/Vec2d/Vec2d.h @@ -17,7 +17,8 @@ inline double_t toRadians(double_t degrees) { class Vec2d { private: - std::default_random_engine random; + std::mt19937 mtRand; + std::uniform_real_distribution smallAngleGen; float_t hypotenuse; double_t x, y; const float_t bumpSpeedIncrease = 1.05; @@ -25,11 +26,16 @@ private: public: Vec2d(float_t hypotenuse) : hypotenuse(hypotenuse) { std::random_device rd; - random = std::default_random_engine(rd()); - int sign = random() % 2 == 0 ? -1 : 1; - double_t angle = toRadians(random() % 6000 / 100 - 30); + mtRand = std::mt19937(rd()); + std::uniform_int_distribution ints(0, 1); + int sign = ints(mtRand) ? -1 : 1; + + std::uniform_real_distribution angleGen(3, 60); + double_t angle = toRadians(angleGen(mtRand)); x = cos(angle) * sign * hypotenuse; y = sin(angle) * sign * hypotenuse; + + smallAngleGen = std::uniform_real_distribution(15, 20); } void applyVector(Sint16 *ox, Sint16 *oy) const { @@ -55,7 +61,7 @@ public: x = -x; double angle = 0; if (paddleDirection != PaddleDirection::NOT_MOVING) { - double_t degrees = rand() % 500 / 100 + 15; + double_t degrees = smallAngleGen(mtRand); degrees *= paddleDirection == PaddleDirection::MOVING_UP ? -1 : 1; angle = toRadians(degrees);