From 42313b010a972f78c7e392c3bfdbca2b50b6a69f Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 6 Oct 2021 11:24:36 +0200 Subject: [PATCH] Removed random engine, using libscnumerics instead --- src/ScreensaverPlugin.cpp | 17 +++++++++-------- src/ScreensaverPlugin.hpp | 3 --- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ScreensaverPlugin.cpp b/src/ScreensaverPlugin.cpp index ca204cc..2d5de93 100644 --- a/src/ScreensaverPlugin.cpp +++ b/src/ScreensaverPlugin.cpp @@ -7,6 +7,7 @@ // #include "ScreensaverPlugin.hpp" +#include void ScreensaverPlugin::setup(cairo_t* context, const cairo_rectangle_t& rect) { _c = context; @@ -33,8 +34,8 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t std::uniform_real_distribution dx {rect.x, rect.width}; std::uniform_real_distribution dy {rect.y, rect.height}; double v1, v2; - v1 = dx(_eng); - v2 = dx(_eng); + v1 = dx(sc::random::instance().engine()); + v2 = dx(sc::random::instance().engine()); if (v1 < v2) { r.x = v1; r.width = v2 - v1; @@ -42,8 +43,8 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t r.x = v2; r.width = v1 - v2; } - v1 = dy(_eng); - v2 = dy(_eng); + v1 = dy(sc::random::instance().engine()); + v2 = dy(sc::random::instance().engine()); if (v1 < v2) { r.y = v1; r.height = v2 - v1; @@ -56,22 +57,22 @@ cairo_rectangle_t ScreensaverPlugin::random_rect_in_rect(const cairo_rectangle_t double ScreensaverPlugin::random_x() { std::uniform_real_distribution dist {0, _r.width}; - return dist(_eng); + return dist(sc::random::instance().engine()); } double ScreensaverPlugin::random_y() { std::uniform_real_distribution dist {0, _r.height}; - return dist(_eng); + return dist(sc::random::instance().engine()); } double ScreensaverPlugin::random01() { std::uniform_real_distribution dist {}; - return dist(_eng); + return dist(sc::random::instance().engine()); } double ScreensaverPlugin::random_between(double v1, double v2) { std::uniform_real_distribution dist {v1, v2}; - return dist(_eng); + return dist(sc::random::instance().engine()); } void ScreensaverPlugin::rounded_rect(const cairo_rectangle_t& rect, double radius) { diff --git a/src/ScreensaverPlugin.hpp b/src/ScreensaverPlugin.hpp index 2ff05bb..65ac60f 100644 --- a/src/ScreensaverPlugin.hpp +++ b/src/ScreensaverPlugin.hpp @@ -10,7 +10,6 @@ #define _ScreensaverPlugin_H_ #include -#include class ScreensaverPlugin { public: @@ -26,8 +25,6 @@ class ScreensaverPlugin { protected: cairo_t* _c {nullptr}; cairo_rectangle_t _r {}; - std::random_device _dev {}; - std::default_random_engine _eng {_dev()}; void make_black(); cairo_rectangle_t random_rect();