从数组中随机抽取指定数量的元素(可以选择是否允许重复) Randomly selects a specified number of elements from an array (chooses with/without replacement)
源数组 / Source array
需要抽取的元素数量 / Number of elements to sample
是否允许重复抽取,默认为false / Whether to allow replacement, defaults to false
包含随机抽取元素的数组 / Array containing randomly sampled elements
// 默认不允许重复// No replacement by defaultsample([1, 2, 3, 4, 5], 3)// 显式指定允许重复// Explicitly allow replacementsample([1, 2, 3, 4, 5], 3, true) Copy
// 默认不允许重复// No replacement by defaultsample([1, 2, 3, 4, 5], 3)// 显式指定允许重复// Explicitly allow replacementsample([1, 2, 3, 4, 5], 3, true)
从数组中随机抽取指定数量的元素(可以选择是否允许重复) Randomly selects a specified number of elements from an array (chooses with/without replacement)