示例#1
0
 /**
  * Shuffles the specified big array using the specified pseudorandom number generator.
  *
  * @param a the big array to be shuffled.
  * @param random a pseudorandom number generator (please use a <a
  *     href="http://dsiutils.dsi.unimi.it/docs/it/unimi/dsi/util/XorShiftStarRandom.html">XorShift*</a>
  *     generator).
  * @return <code>a</code>.
  */
 public static boolean[][] shuffle(final boolean[][] a, final Random random) {
   for (long i = length(a); i-- != 0; ) {
     final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1);
     final boolean t = get(a, i);
     set(a, i, get(a, p));
     set(a, p, t);
   }
   return a;
 }
示例#2
0
 /**
  * Shuffles the specified big array fragment using the specified pseudorandom number generator.
  *
  * @param a the big array to be shuffled.
  * @param from the index of the first element (inclusive) to be shuffled.
  * @param to the index of the last element (exclusive) to be shuffled.
  * @param random a pseudorandom number generator (please use a <a
  *     href="http://dsiutils.dsi.unimi.it/docs/it/unimi/dsi/util/XorShiftStarRandom.html">XorShift*</a>
  *     generator).
  * @return <code>a</code>.
  */
 public static boolean[][] shuffle(
     final boolean[][] a, final long from, final long to, final Random random) {
   for (long i = to - from; i-- != 0; ) {
     final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1);
     final boolean t = get(a, from + i);
     set(a, from + i, get(a, from + p));
     set(a, from + p, t);
   }
   return a;
 }