@supuwoerc/toolkit
    Preparing search index...

    Function sampleWithReplacement

    • 从数组中随机抽取指定数量的元素(允许重复) Randomly selects a specified number of elements from an array (with replacement)

      Type Parameters

      • T

      Parameters

      • array: T[]

        源数组 / Source array

      • quantity: number

        需要抽取的元素数量 / Number of elements to sample

      Returns T[]

      包含随机抽取元素的数组 / Array containing randomly sampled elements

      // 返回可能包含重复元素的3个随机元素
      // Returns 3 random elements that may contain duplicates
      sampleWithReplacement([1, 2, 3, 4, 5], 3)