]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::shuffle
authoradam4130 <adam4130@users.noreply.github.com>
Sat, 8 Jun 2019 04:15:05 +0000 (22:15 -0600)
committeradam4130 <adam4130@users.noreply.github.com>
Sat, 8 Jun 2019 04:15:05 +0000 (22:15 -0600)
examples/step-63/step-63.cc

index a97292ca7e725a4dfbc1993d74f04abcfc5f7388..fec0f3378837ccd3aef7c80a71ab5feda8aa8cc8 100644 (file)
@@ -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;
   }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.