Sample multiple random elements uniformly without replacement from a container of unknown length. If
more samples are requested than are in the set, the function returns as many items as it can.
Samples one element uniformly at random from slice, excluding any element
equal to excluded. Returns None if the slice is empty or every element
equals excluded.
Linear-scan implementation of sample_single_excluding. Counts non-excluded
entries, then picks the k-th. Wins for very small slices (n <= 3) where
the per-trial overhead of rejection sampling exceeds the cost of a tiny
filter. Exposed so benchmarks can compare strategies directly.
Sample one element uniformly from an iterator, excluding any element equal
to excluded. Returns None if the iterator is empty or every element
equals excluded.
Rejection-sampling implementation of sample_single_excluding. Picks a
uniform index, accepts if not equal to excluded. Wins at n >= 4 and is
essentially constant time when excluded appears 0 or 1 times. Falls
through to sample_single_excluding_iteration after at most 16 consecutive
matches (or n, whichever is smaller), which also returns None when
every element matches. Exposed so benchmarks can compare strategies
directly.