@Test public void testSubRandom_Int_Int(){ for (int j = 0; j < 10; j++) { int[] r = Randoms.subRandom(0, 5, 4); for (int i = 0; i < r.length; i++) { System.out.print(r[i] + "\t"); } System.out.println("lenght:"+r.length); } }
public static int[] subRandom(int min, int max, int subLength){ int size = max - min + 1; Asserts.isTrue(size > 0); int[] randoms = new int[size]; for(int i = 0; i < size; i++){ randoms[i] = min + i; } if(size <= subLength){ return randoms; } int temp1, temp2, len = randoms.length; int subRandoms[] = new int[subLength]; for(int i = 0; i < subLength; i++) { temp1 = Math.abs(nextInt()) % len; subRandoms[i] = randoms[temp1]; temp2 = randoms[temp1]; randoms[temp1] = randoms[len-1]; randoms[len-1] = temp2; len--; } return subRandoms; }
Randoms { public static int[] subRandom(int min, int max, int subLength){ int size = max - min + 1; Asserts.isTrue(size > 0); int[] randoms = new int[size]; for(int i = 0; i < size; i++){ randoms[i] = min + i; } if(size <= subLength){ return randoms; } int temp1, temp2, len = randoms.length; int subRandoms[] = new int[subLength]; for(int i = 0; i < subLength; i++) { temp1 = Math.abs(nextInt()) % len; subRandoms[i] = randoms[temp1]; temp2 = randoms[temp1]; randoms[temp1] = randoms[len-1]; randoms[len-1] = temp2; len--; } return subRandoms; } }
Randoms { public static int[] subRandom(int min, int max, int subLength){ int size = max - min + 1; Asserts.isTrue(size > 0); int[] randoms = new int[size]; for(int i = 0; i < size; i++){ randoms[i] = min + i; } if(size <= subLength){ return randoms; } int temp1, temp2, len = randoms.length; int subRandoms[] = new int[subLength]; for(int i = 0; i < subLength; i++) { temp1 = Math.abs(nextInt()) % len; subRandoms[i] = randoms[temp1]; temp2 = randoms[temp1]; randoms[temp1] = randoms[len-1]; randoms[len-1] = temp2; len--; } return subRandoms; }  }
Randoms { public static int[] subRandom(int min, int max, int subLength){ int size = max - min + 1; Asserts.isTrue(size > 0); int[] randoms = new int[size]; for(int i = 0; i < size; i++){ randoms[i] = min + i; } if(size <= subLength){ return randoms; } int temp1, temp2, len = randoms.length; int subRandoms[] = new int[subLength]; for(int i = 0; i < subLength; i++) { temp1 = Math.abs(nextInt()) % len; subRandoms[i] = randoms[temp1]; temp2 = randoms[temp1]; randoms[temp1] = randoms[len-1]; randoms[len-1] = temp2; len--; } return subRandoms; }  static int nextInt(); static int nextInt(int max); static int random(int min, int max); static int[] subRandom(int min, int max, int subLength); static char nextCharacter(); static String nextString(int max); static String nextString(int min, int max); static void main(String[] args); }
Randoms { public static int[] subRandom(int min, int max, int subLength){ int size = max - min + 1; Asserts.isTrue(size > 0); int[] randoms = new int[size]; for(int i = 0; i < size; i++){ randoms[i] = min + i; } if(size <= subLength){ return randoms; } int temp1, temp2, len = randoms.length; int subRandoms[] = new int[subLength]; for(int i = 0; i < subLength; i++) { temp1 = Math.abs(nextInt()) % len; subRandoms[i] = randoms[temp1]; temp2 = randoms[temp1]; randoms[temp1] = randoms[len-1]; randoms[len-1] = temp2; len--; } return subRandoms; }  static int nextInt(); static int nextInt(int max); static int random(int min, int max); static int[] subRandom(int min, int max, int subLength); static char nextCharacter(); static String nextString(int max); static String nextString(int min, int max); static void main(String[] args); static final Random random; }