Generates a random subset of <code>set</code>, that contains exactly
<code>maxCount</code> elements.

@param <T>
Type of set elements
@param set
Basic set for operation
@param count
Number of items
@return A subset with exactly <code>count</code> elements
766133
public static <T> Set<T> getRandomSubset(Set<T> set, int count) {
		Set<T> result = new HashSet<>();
		HashList<T> opSet = new HashList<>(set);
		while (result.size() < count) {
			int next = rand.nextInt(opSet.size());
			if (!result.contains(opSet.get(next))) {
				result.add(opSet.get(next));
			}
		}
		return result;
	}
998254
public static <T> Stream<Set<T>> combinationsStream(Set<T> elements, int subsetSize) {
        if (subsetSize == 0) {
            return Stream.of(new HashSet<>());
        }
        else if (subsetSize <= elements.size()) {
            Set<T> remainingElements = elements;

            Iterator<T> it = remainingElements.iterator();
            T X = it.next();
            it.remove();

            Stream<Set<T>> combinations = Stream.concat(
                    combinationsStream(remainingElements, subsetSize), //exclude X
                    combinationsStream(remainingElements, subsetSize-1).map(s -> {s.add(X); return s;}) //include X
            );

            remainingElements.add(X);

            return combinations;
        }
        else {
            return Stream.empty();
        }
    }
98511
public static <E extends Enum<E>> Collector<E, ?, EnumSet<E>> toEnumSet(Class<E> enumClass) {
    return Collectors.toCollection(() -> EnumSet.noneOf(enumClass));
  }
748712
public synchronized SamplerResult<T> finishSampling(int count)
    {
        List<Counter<T>> results = Collections.EMPTY_LIST;
        long cardinality = 0;
        if (enabled)
        {
            enabled = false;
            results = summary.topK(count);
            cardinality = hll.cardinality();
        }
        return new SamplerResult<T>(results, cardinality);
    }
929531
public static <T> List<T> repeatEachToSize(final Collection<T> c, final int size) {
        N.checkArgNotNegative(size, "size");
        checkArgument(size == 0 || notNullOrEmpty(c), "Collection can not be empty or null when size > 0");

        if (size == 0 || isNullOrEmpty(c)) {
            return new ArrayList<T>();
        }

        final int n = size / c.size();
        int mod = size % c.size();

        final List<T> result = new ArrayList<>(size);

        for (T e : c) {
            for (int i = 0, len = mod-- > 0 ? n + 1 : n; i < len; i++) {
                result.add(e);
            }

            if (result.size() == size) {
                break;
            }
        }

        return result;
    }
1084567
public static <T> T randomEle(List<T> list) {
		return randomEle(list, list.size());
	}
1466
public static <T> Set<T> toSet(Enumeration<T> self) {
        Set<T> answer = new HashSet<T>();
        while (self.hasMoreElements()) {
            answer.add(self.nextElement());
        }
        return answer;
    }
367795
public static <T> List<T> randomSample(Collection<T> collection, int n) {
		List<T> list = new ArrayList<T>(collection);
		List<T> sample = new ArrayList<T>(n);
		Random random = new Random();
		while(n > 0  &&  !list.isEmpty()) {
			int index = random.nextInt(list.size());
			sample.add(list.get(index));
			int indexLast = list.size() - 1;
			T last = list.remove(indexLast);
			if(index < indexLast) {
				list.set(index, last);
			}
			n--;
		}
		return sample;
	}
1372022
public static <T> T randomEle(List<T> list, int limit) {
		return list.get(randomInt(limit));
	}
105320
public static <E extends Enum<E> & ByteEnum> int setToInt (Set<E> set)
    {
        int flags = 0;
        for (E value : set) {
            flags |= toIntFlag(value);
        }
        return flags;
    }
626413
def k_subsets(set_, k):
    
    ensure_countable(set_)

    if not isinstance(k, Integral):
        raise TypeError("subset cardinality must be a number")
    if not (k >= 0):
        raise ValueError("subset cardinality must be positive")
    if not (k <= len(set_)):
        raise ValueError("subset cardinality must not exceed set cardinality")

    result = combinations(set_, k)
    return _harmonize_subset_types(set_, result)
624800
public static final <T> boolean intersect(Collection<Set<T>> sets)
    {
        Set<T> set = intersection(sets);
        return !set.isEmpty();
    }
252775
public static <T> Set<T> intersection(Set<T>... sets) {
		return intersection(Arrays.asList(sets));
	}
1277693
public Set<SortedSet<T>> allSubsets(final SortedSet<T> set) {
        final Set<SortedSet<T>> subsets = new LinkedHashSet<>();
        allSubsets(set, this.rootNodes, subsets);
        return subsets;
    }
1161265
public static <T> Set<T> iterableToSet(Iterable<T> iterable) {
        if (iterable == null) {
            return Collections.emptySet();
        }
        if (iterable instanceof Set) {
            return (Set<T>) iterable;
        }
        Iterator<T> i = iterable.iterator();
        if (i.hasNext()) {
            Set<T> list = new HashSet<>();
            while (i.hasNext()) {
                list.add(i.next());
            }
            return list;
        }
        return Collections.emptySet();
    }
550711
public static <T> Set<T> getSet(Collection<T> collection) {
    Set<T> set = new LinkedHashSet<T>();
    set.addAll(collection);

    return set;
  }
942439
public Histogram<T> setBucketCount( int count ) {
        if (count != this.bucketCount) {
            this.bucketCount = count;
            this.bucketWidth = null;
            this.buckets.clear();
        }
        return this;
    }