1 4 package dso.concurrency; 5 6 import java.util.Random ; 7 8 13 public class Shuffler { 14 15 private int shuffleSize = 0; 16 private Random random = new Random (); 17 int[] positions; 18 19 public Shuffler(int shuffleSize) { 20 this.shuffleSize = shuffleSize; 21 positions = new int[shuffleSize]; 22 for (int i=0; i<shuffleSize; i++) { 23 positions[i] = i; 24 } 25 } 26 27 public int[] shuffleOrder() { 28 29 for (int i=0; i<shuffleSize; i++) { 30 int changingPosition = random.nextInt(shuffleSize); 31 int swappedValue = positions[i]; 32 positions[i] = positions[changingPosition]; 33 positions[changingPosition] = swappedValue; 34 } 35 return positions; 36 } 37 } 38 | Popular Tags |