从数组中随机抽取指定数量的不重复元素 Randomly selects a specified number of unique elements from an array (without replacement)
源数组 / Source array
需要抽取的元素数量 / Number of elements to sample
包含随机抽取不重复元素的数组 / Array containing randomly sampled unique elements
当请求数量超过数组长度时抛出错误 / Throws error when requested quantity exceeds array length
// 返回3个不重复的随机元素// Returns 3 unique random elementssampleWithoutReplacement([1, 2, 3, 4, 5], 3) Copy
// 返回3个不重复的随机元素// Returns 3 unique random elementssampleWithoutReplacement([1, 2, 3, 4, 5], 3)
从数组中随机抽取指定数量的不重复元素 Randomly selects a specified number of unique elements from an array (without replacement)