changeset 5:1ba6ea44e5f9

slight fix of RandomPermutationGenerator, which should re-shuffle the original array, not the previous permutation
author Peter Mehlitz <pcmehlitz@gmail.com>
date Thu, 05 Feb 2015 19:13:42 -0800
parents d0a0ff1c0e10
children 3a19eedcc13d
files src/main/gov/nasa/jpf/util/RandomPermutationGenerator.java
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/gov/nasa/jpf/util/RandomPermutationGenerator.java	Thu Feb 05 18:53:33 2015 -0800
+++ b/src/main/gov/nasa/jpf/util/RandomPermutationGenerator.java	Thu Feb 05 19:13:42 2015 -0800
@@ -33,10 +33,13 @@
   protected int seed;
   protected Random rand;
   
+  protected int[] orig;
+  
   public RandomPermutationGenerator (int nElements, int nPermutations, int seed){
     super(nElements);
     this.nPermutations = nPermutations;
     rand = new Random(seed);
+    orig = permutation.clone();
   }
   
   @Override
@@ -58,13 +61,12 @@
       return permutation;
       
     } else if (nGenerated < nPermutations){
-      int[] perm = permutation.clone();
+      permutation = orig.clone();
       for (int i=0; i<nElements; i++){
         int r = i + rand.nextInt( nElements-i);  // i <= r < nElements-1
-        swap(perm, r, i);
+        swap(permutation, r, i);
       }        
       nGenerated++;
-      permutation = perm;
       return permutation;
         
     } else {