01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package dso.concurrency;
05:
06: import java.util.Random;
07:
08: /**
09: * Created by Alan Brown
10: * Date: May 17, 2005
11: * Time: 1:48:02 PM
12: */
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: }
|