From 6d389e46b61a9d9c5e5024d4d879b21edc288163 Mon Sep 17 00:00:00 2001 From: adam4130 Date: Fri, 7 Jun 2019 22:15:05 -0600 Subject: [PATCH] Use std::shuffle --- examples/step-63/step-63.cc | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/examples/step-63/step-63.cc b/examples/step-63/step-63.cc index a97292ca7e..fec0f33788 100644 --- a/examples/step-63/step-63.cc +++ b/examples/step-63/step-63.cc @@ -319,13 +319,9 @@ namespace Step63 ordered_cells.push_back(cell->index()); std::mt19937 random_number_generator; - for (unsigned int i = 1; i < ordered_cells.size(); ++i) - { - const unsigned int j = - std::uniform_int_distribution<>(0, i)(random_number_generator); - if (i != j) - std::swap(ordered_cells[i], ordered_cells[j]); - } + std::shuffle(ordered_cells.begin(), + ordered_cells.end(), + random_number_generator); return ordered_cells; } @@ -342,13 +338,9 @@ namespace Step63 ordered_cells.push_back(cell->index()); std::mt19937 random_number_generator; - for (unsigned int i = 1; i < ordered_cells.size(); ++i) - { - const unsigned int j = - std::uniform_int_distribution<>(0, i)(random_number_generator); - if (i != j) - std::swap(ordered_cells[i], ordered_cells[j]); - } + std::shuffle(ordered_cells.begin(), + ordered_cells.end(), + random_number_generator); return ordered_cells; } -- 2.39.5