The type of elements in the array / 数组元素的类型
The array to sample from. 要取样的数组
The number of elements to sample. 要取样的元素数量
An array of random elements from the array. 数组中的随机元素数组
O(n) time complexity where n is the size parameter. Uses Fisher-Yates partial shuffle for unbiased sampling
O(n) 时间复杂度,其中 n 为 size 参数。使用 Fisher-Yates 部分洗牌算法实现无偏取样
Implementation uses Fisher-Yates partial shuffle, which requires a full shallow copy of the array (O(n) memory). When sampling a very small subset from an extremely large array, memory usage scales with array size rather than sample size.
实现基于 Fisher-Yates 部分洗牌算法,需要先对数组进行浅拷贝(O(n) 内存)。当从超大数组中抽取极小样本时,内存消耗与数组大小成正比,而非样本大小。
Gets n random elements from an array.
If n is greater than the array length, returns all elements in random order. If n is 0 or negative, returns an empty array.
从数组中获取 n 个随机元素。
如果 n 大于数组长度,则以随机顺序返回所有元素。 如果 n 为 0 或负数,则返回空数组。