Replace std::rand with <random>

This commit is contained in:
Chris Thrasher 2023-03-03 21:40:36 -07:00
parent 42a53cfb1d
commit a100f847d5
3 changed files with 6 additions and 5 deletions

View File

@ -9,7 +9,6 @@ Checks: >
-clang-analyzer-optin.cplusplus.VirtualCall, -clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-optin.osx.*, -clang-analyzer-optin.osx.*,
-clang-analyzer-osx.*, -clang-analyzer-osx.*,
-clang-analyzer-security.insecureAPI.rand,
-clang-analyzer-unix.Malloc, -clang-analyzer-unix.Malloc,
-misc-const-correctness, -misc-const-correctness,
-misc-misplaced-const, -misc-misplaced-const,

View File

@ -279,8 +279,9 @@ public:
{ {
// Spread the coordinates from -480 to +480 // Spread the coordinates from -480 to +480
// So they'll always fill the viewport at 800x600 // So they'll always fill the viewport at 800x600
m_pointCloud[i].position.x = static_cast<float>(rand() % 960) - 480.f; std::uniform_real_distribution<float> positionDistribution(-480, 480);
m_pointCloud[i].position.y = static_cast<float>(rand() % 960) - 480.f; m_pointCloud[i].position.x = positionDistribution(rng);
m_pointCloud[i].position.y = positionDistribution(rng);
} }
// Load the texture // Load the texture

View File

@ -32,8 +32,8 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cctype> #include <cctype>
#include <cstdlib>
#include <ostream> #include <ostream>
#include <random>
namespace sf::priv namespace sf::priv
@ -63,7 +63,8 @@ bool SoundFileWriterOgg::open(const std::filesystem::path& filename, unsigned in
m_channelCount = channelCount; m_channelCount = channelCount;
// Initialize the ogg/vorbis stream // 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<int>::max())(rng));
vorbis_info_init(&m_vorbis); vorbis_info_init(&m_vorbis);
// Setup the encoder: VBR, automatic bitrate management // Setup the encoder: VBR, automatic bitrate management