/** * Selects a random subset of {@code n} longs from a given set of longs. If fewer than {@code n} * items can be selected the whole set is returned. * * * @param set the set of items to select from * @param num The number of random items to add. * @param random a random number generator to be used. * @return An item selector that selects the items selected by {@code base} plus an additional * {@code nRandom} items. */ public static LongSet randomSubset(LongSet set, int num, Random random) { return randomSubset(set, num, LongSortedSets.EMPTY_SET, random); }
/** * Pick a random subset of a set of items. * @param items The set of items to pick from. * @param n the number of items to select. * @return A random subset of `items` of size at most `n`. */ public LongSet pickRandom(Set<Long> items, int n) { return LongUtils.randomSubset(LongUtils.asLongSet(items), n, random); }
/** * Selects a random subset of {@code n} longs from a given set of longs. If fewer than {@code n} * items can be selected the whole set is returned. * * * @param set the set of items to select from * @param num The number of random items to add. * @param random a random number generator to be used. * @return An item selector that selects the items selected by {@code base} plus an additional * {@code nRandom} items. */ public static LongSet randomSubset(LongSet set, int num, Random random) { return randomSubset(set, num, LongSortedSets.EMPTY_SET, random); }
candidates.addAll(LongUtils.randomSubset(dao.getEntityIds(CommonTypes.ITEM), listSize - 1, excludes, rng));