@supuwoerc/toolkit
    Preparing search index...

    Function sampleWithoutReplacement

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

      Type Parameters

      • T

      Parameters

      • array: T[]

        源数组 / Source array

      • quantity: number

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

      Returns T[]

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

      当请求数量超过数组长度时抛出错误 / Throws error when requested quantity exceeds array length

      // 返回3个不重复的随机元素
      // Returns 3 unique random elements
      sampleWithoutReplacement([1, 2, 3, 4, 5], 3)