improved sample function, specifically when sampling without replacement