Skip to content

Commit ab755ff

Browse files
committed
modify shuffle int[]
1 parent 42037e9 commit ab755ff

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cn/trinea/android/common/util/RandomUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,20 @@ public static boolean shuffle(Object[] objArray, int shuffleCount) {
172172
* @param shuffleCount
173173
* @return
174174
*/
175-
public static boolean shuffle(int[] intArray, int shuffleCount) {
175+
public static int[] shuffle(int[] intArray, int shuffleCount) {
176176
int length;
177177
if (intArray == null || shuffleCount < 0 || (length = intArray.length) < shuffleCount) {
178-
return false;
178+
return null;
179179
}
180180

181+
int[] out = new int[shuffleCount];
181182
for (int i = 1; i <= shuffleCount; i++) {
182183
int random = getRandom(length - i);
184+
out[i - 1] = intArray[random];
183185
int temp = intArray[length - i];
184186
intArray[length - i] = intArray[random];
185187
intArray[random] = temp;
186188
}
187-
return true;
189+
return out;
188190
}
189191
}

0 commit comments

Comments
 (0)