From ac7e90487ab882a92522d423790531c579eb2d56 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Sat, 11 Feb 2023 11:51:36 +0100 Subject: [PATCH 1/2] :bug: std::rand replaced by std::mt19937_64 --- .../fiction/technology/charge_distribution_surface.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/fiction/technology/charge_distribution_surface.hpp b/include/fiction/technology/charge_distribution_surface.hpp index 808052de6..00e9ea2d9 100644 --- a/include/fiction/technology/charge_distribution_surface.hpp +++ b/include/fiction/technology/charge_distribution_surface.hpp @@ -758,12 +758,9 @@ class charge_distribution_surface : public Lyt if (!candidates.empty()) { - const auto random_index = - static_cast(std::rand()) % // NOLINT: we use rand() due to its performance advantage; we do - // not need cryptographic security here - candidates.size(); - - const auto random_element = index_vector[candidates[random_index]]; + static std::mt19937_64 generator(std::random_device{}()); + std::uniform_int_distribution dist(0, candidates.size() - 1); + const auto random_element = index_vector[candidates[dist(generator)]]; strg->cell_charge[random_element] = sidb_charge_state::NEGATIVE; negative_indices.push_back(random_element); From cad067b3704021ef5bc257eb74b4b845e4086995 Mon Sep 17 00:00:00 2001 From: ClangFormat Date: Sat, 11 Feb 2023 10:57:29 +0000 Subject: [PATCH 2/2] :art: ClangFormat changes Signed-off-by: ClangFormat --- include/fiction/technology/charge_distribution_surface.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/fiction/technology/charge_distribution_surface.hpp b/include/fiction/technology/charge_distribution_surface.hpp index 00e9ea2d9..af1799bd9 100644 --- a/include/fiction/technology/charge_distribution_surface.hpp +++ b/include/fiction/technology/charge_distribution_surface.hpp @@ -758,10 +758,10 @@ class charge_distribution_surface : public Lyt if (!candidates.empty()) { - static std::mt19937_64 generator(std::random_device{}()); + static std::mt19937_64 generator(std::random_device{}()); std::uniform_int_distribution dist(0, candidates.size() - 1); - const auto random_element = index_vector[candidates[dist(generator)]]; - strg->cell_charge[random_element] = sidb_charge_state::NEGATIVE; + const auto random_element = index_vector[candidates[dist(generator)]]; + strg->cell_charge[random_element] = sidb_charge_state::NEGATIVE; negative_indices.push_back(random_element); strg->system_energy += -(this->get_local_potential_by_index(random_element).value());