Skip to content

Commit

Permalink
Correct Fisher-Yates-Durstenfeld
Browse files Browse the repository at this point in the history
  • Loading branch information
noncombatant committed May 15, 2023
1 parent 4f0365d commit a99a6d6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion robotfindskitten.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ static bool StringsEqual(const char* a, const char* b) {
}

static void Shuffle(char** array, size_t count) {
for (size_t i = 0; i < count - 1; ++i) {
assert(count > 2);
for (size_t i = 0; i < count - 2; ++i) {
const size_t j = i + ((size_t)random() % (count - i));
assert(i <= j && j < count);
char* temp = array[i];
array[i] = array[j];
array[j] = temp;
Expand Down

0 comments on commit a99a6d6

Please sign in to comment.