/** * Shuffle the data. This uses a Fischer-Yates shuffle to uniformly permute * (subject to limitations of the PRNG) the data. The arrays are repacked * to eliminate free slots prior to shuffling. * * @param rng The random number generator to use. */ void shuffle(Random rng) { repack(); // do a reverse Fisher-Yates shuffle on the arrays final int np = nprefs; for (int i = 0; i < np - 1; i++) { // swap w/ j s.t. i <= j < end int j = i + rng.nextInt(np - i); assert j >= i; assert j < np; swap(i, j); } }
/** * Build the packed rating data. This first moves records from the end to fill * any released but not reused slots. * * @return The packed rating data structure. */ @Override public PackedRatingData build() { repack(); trim(); return internalBuild(); } }
/** * Shuffle the data. This uses a Fischer-Yates shuffle to uniformly permute * (subject to limitations of the PRNG) the data. The arrays are repacked * to eliminate free slots prior to shuffling. * * @param rng The random number generator to use. */ void shuffle(Random rng) { repack(); // do a reverse Fisher-Yates shuffle on the arrays final int np = nprefs; for (int i = 0; i < np - 1; i++) { // swap w/ j s.t. i <= j < end int j = i + rng.nextInt(np - i); assert j >= i; assert j < np; swap(i, j); } }
/** * Build the packed rating data. This first moves records from the end to fill * any released but not reused slots. * * @return The packed rating data structure. */ @Override public PackedRatingData build() { repack(); trim(); return internalBuild(); } }