diff options
author | David Robillard <d@drobilla.net> | 2024-07-17 09:14:35 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-07-17 09:39:29 -0400 |
commit | 5d46cb1a9e1bb2eb989c364805903e1cd98cea30 (patch) | |
tree | 2a2eac469599f0868549260b13e260ccd1126c7e | |
parent | e218739bbb66c9a4d2d8860a3322f2eb91b6c32e (diff) | |
download | patchage-5d46cb1a9e1bb2eb989c364805903e1cd98cea30.tar.gz patchage-5d46cb1a9e1bb2eb989c364805903e1cd98cea30.tar.bz2 patchage-5d46cb1a9e1bb2eb989c364805903e1cd98cea30.zip |
Avoid use of rand()
-rw-r--r-- | .clang-tidy | 2 | ||||
-rw-r--r-- | src/Canvas.cpp | 6 | ||||
-rw-r--r-- | src/Canvas.hpp | 3 |
3 files changed, 6 insertions, 5 deletions
diff --git a/.clang-tidy b/.clang-tidy index 094d8d1..864f349 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,8 +17,6 @@ Checks: > -bugprone-multi-level-implicit-pointer-conversion, -cert-dcl21-cpp, -cert-dcl50-cpp, - -cert-msc30-c, - -cert-msc50-cpp, -clang-analyzer-optin.cplusplus.VirtualCall, -concurrency-mt-unsafe, -cppcoreguidelines-avoid-const-or-ref-data-members, diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 76bd0bd..5590a5b 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -40,7 +40,6 @@ PATCHAGE_RESTORE_WARNINGS #include <sigc++/signal.h> #include <cassert> -#include <cstdlib> #include <functional> #include <optional> #include <set> @@ -100,6 +99,7 @@ Canvas::Canvas(ILog& log, ActionSink& action_sink, int width, int height) : Ganv::Canvas(width, height) , _log(log) , _action_sink(action_sink) + , _rng(width + height) { signal_event.connect(sigc::mem_fun(this, &Canvas::on_event)); signal_connect.connect(sigc::mem_fun(this, &Canvas::on_connect)); @@ -146,8 +146,8 @@ Canvas::create_port(Configuration& conf, Coord loc; if (!conf.get_module_location(client_name, module_type, loc)) { // No position saved, come up with a pseudo-random one - loc.x = 20 + rand() % 640; - loc.y = 20 + rand() % 480; + loc.x = static_cast<double>(20 + _rng() % 640); + loc.y = static_cast<double>(20 + _rng() % 480); conf.set_module_location(client_name, module_type, loc); } diff --git a/src/Canvas.hpp b/src/Canvas.hpp index 81e4d61..ae713bc 100644 --- a/src/Canvas.hpp +++ b/src/Canvas.hpp @@ -17,6 +17,7 @@ PATCHAGE_RESTORE_WARNINGS #include <gdk/gdk.h> #include <map> +#include <random> namespace Ganv { class Node; @@ -74,6 +75,8 @@ private: ActionSink& _action_sink; PortIndex _port_index; ModuleIndex _module_index; + + std::minstd_rand _rng; }; } // namespace patchage |