从数组中随机抽取指定数量的元素(允许重复) Randomly selects a specified number of elements from an array (with replacement)
源数组 / Source array
需要抽取的元素数量 / Number of elements to sample
包含随机抽取元素的数组 / Array containing randomly sampled elements
// 返回可能包含重复元素的3个随机元素// Returns 3 random elements that may contain duplicatessampleWithReplacement([1, 2, 3, 4, 5], 3) Copy
// 返回可能包含重复元素的3个随机元素// Returns 3 random elements that may contain duplicatessampleWithReplacement([1, 2, 3, 4, 5], 3)
从数组中随机抽取指定数量的元素(允许重复) Randomly selects a specified number of elements from an array (with replacement)