Explorar o código

Fix permutation::random

Olivier Marty %!s(int64=8) %!d(string=hai) anos
pai
achega
c8dff76a50
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      src/permutation.cpp

+ 2 - 2
src/permutation.cpp

@@ -20,9 +20,9 @@ void permutation::transpose(int i, int j) {
 
 // TODO rapport : dire qu'on garde l'invariant pi[0] = 0
 void permutation::random() {
-  // Knuth shuffle
+  // Knuth Fisher Yates shuffle
   // there is a bias due to the use of rand()%_
-  for(int i = 1; i < size; i++)
+  for(int i = size-1; i > 1; i--)
     transpose(i, 1+rand()%i);
 }