From a100f847d5a7dbd2a525ce534e60284e892067a4 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 3 Mar 2023 21:40:36 -0700 Subject: [PATCH] Replace `std::rand` with `` --- .clang-tidy | 1 - examples/shader/Shader.cpp | 5 +++-- src/SFML/Audio/SoundFileWriterOgg.cpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0eab94b8..34f52d9d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: > -clang-analyzer-optin.cplusplus.VirtualCall, -clang-analyzer-optin.osx.*, -clang-analyzer-osx.*, - -clang-analyzer-security.insecureAPI.rand, -clang-analyzer-unix.Malloc, -misc-const-correctness, -misc-misplaced-const, diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 8be2f478..36f612d6 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -279,8 +279,9 @@ public: { // Spread the coordinates from -480 to +480 // So they'll always fill the viewport at 800x600 - m_pointCloud[i].position.x = static_cast(rand() % 960) - 480.f; - m_pointCloud[i].position.y = static_cast(rand() % 960) - 480.f; + std::uniform_real_distribution positionDistribution(-480, 480); + m_pointCloud[i].position.x = positionDistribution(rng); + m_pointCloud[i].position.y = positionDistribution(rng); } // Load the texture diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index 00e52c55..feea52f5 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include namespace sf::priv @@ -63,7 +63,8 @@ bool SoundFileWriterOgg::open(const std::filesystem::path& filename, unsigned in m_channelCount = channelCount; // Initialize the ogg/vorbis stream - ogg_stream_init(&m_ogg, std::rand()); + static std::mt19937 rng(std::random_device{}()); + ogg_stream_init(&m_ogg, std::uniform_int_distribution(0, std::numeric_limits::max())(rng)); vorbis_info_init(&m_vorbis); // Setup the encoder: VBR, automatic bitrate management