From 983b23046cdbd09b3c3924bdc91c54db179e21c2 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 26 Jun 2014 21:40:29 +0200 Subject: [PATCH] bugfix in CCArray.shuffle --- core/CCArray.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/CCArray.ml b/core/CCArray.ml index 4ddbe08f..53ee7fba 100644 --- a/core/CCArray.ml +++ b/core/CCArray.ml @@ -159,11 +159,11 @@ let rec _exists2 p a1 a2 i1 i2 j1 = (* shuffle a[i...j[ using the given int random generator See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle *) let _shuffle _rand_int a i j = - for k = i to j do - let l = _rand_int k in + for k = j-1 downto i+1 do + let l = _rand_int (k+1) in let tmp = a.(l) in a.(l) <- a.(k); - a.(l) <- tmp; + a.(k) <- tmp; done let _choose a i j st =