Skip to main content

sampleSize

_.sampleSize(n, collection) # Ⓢ [Ⓣ][1] Ⓝ

Gets n random elements at unique keys from collection up to the



size of collection.

Since​

4.0.0

Arguments​

  1. n (number): The number of elements to sample.
  2. collection (Array|Object): The collection to sample.

Returns​

(Array): Returns the random elements.

Example​

_.sampleSize(2, [1, 2, 3]);
// => [3, 1]

_.sampleSize(4, [1, 2, 3]);
// => [2, 3, 1]