Skip to content

Commit

Permalink
Improve random number generation
Browse files Browse the repository at this point in the history
  • Loading branch information
chin123 committed Jul 3, 2019
1 parent 3e002f9 commit 2b1c21f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cubeui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unordered_map>
#include <ctime>
#include <limits>
#include <random>

using std::cout;
using std::endl;
Expand Down Expand Up @@ -102,11 +103,15 @@ char* CubeUi::scramble()
while (sol == NULL) {
std::random_shuffle(corners, corners+8);
std::random_shuffle(edges, edges+12);
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist3(0,2);
std::uniform_int_distribution<std::mt19937::result_type> dist2(0,1);
for (int i = 0; i < 8; i++) {
std::rotate(corners[i], corners[i]+(rand()%3), corners[i]+3);
std::rotate(corners[i], corners[i]+dist3(rng), corners[i]+3);
}
for (int i = 0; i < 12; i++) {
std::rotate(edges[i], edges[i]+(rand()%2), edges[i]+2);
std::rotate(edges[i], edges[i]+dist2(rng), edges[i]+2);
}
setupFaces(corners, edges);
int count = 0;
Expand Down

0 comments on commit 2b1c21f

Please sign in to comment.