public static AddressSet randomSubset(AddressSetView addresses, long k, TaskMonitor monitor)
			throws CancelledException {
		List<Long> sortedRandom = generateRandomIntegerSubset(addresses.getNumAddresses(), k);
		Collections.sort(sortedRandom);
		AddressSet randomAddresses = new AddressSet();
		AddressIterator iter = addresses.getAddresses(true);
		int addressesAdded = 0;
		int addressesVisited = 0;
		int listIndex = 0;
		while (iter.hasNext() && addressesAdded < k) {
			monitor.checkCancelled();
			Address addr = iter.next();
			if (sortedRandom.get(listIndex) == addressesVisited) {
				randomAddresses.add(addr);
				addressesAdded += 1;
				listIndex += 1;
			}
			addressesVisited += 1;
		}
		return randomAddresses;
	}
This method generates a random subset of size {@code k} of {@code addresses}.
<p>
The parameter {@code k} can be of type {@code long}, but you will probably run out of heap
space for large values.

@param addresses addresses
@param k size of random subset to generate
@param monitor monitor
@return random subset of size k
@throws CancelledException if monitor is canceled
Ghidra/Extensions/MachineLearning/src/main/java/ghidra/machinelearning/functionfinding/RandomSubsetUtils.java