Randomly samples a specified number of unique elements from an array.
Selects random elements from the input array without replacement, ensuring
all returned elements are unique. The sample size is automatically capped
at the array length to prevent errors. Uses a Set-based approach to
guarantee uniqueness of selected indices. Ideal for creating test datasets
or selecting random subsets for validation.
Randomly samples a specified number of unique elements from an array.
Selects random elements from the input array without replacement, ensuring all returned elements are unique. The sample size is automatically capped at the array length to prevent errors. Uses a Set-based approach to guarantee uniqueness of selected indices. Ideal for creating test datasets or selecting random subsets for validation.
Example