Skip to content

Function: randomSample() ​

ts
function randomSample<T>(array, count): T[];

Draw count unique elements without replacement (new array). 无放回随机抽取 count 个不重复元素(新数组)。

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
arrayT[]Source array / 源数组
countnumberSample size / 抽取数量

Returns ​

T[]

Sample / 样本

Example ​

ts
randomSample([1, 2, 3, 4, 5], 3) // => e.g. [2, 5, 1]

Since ​

1.0.0

Released under the MIT License.