sampleSize source npm

_.sampleSize(collection, [n=0])

Gets n random elements from collection.

Arguments

  1. collection (Array|Object)

    The collection to sample.

  2. [n=0] (number)

    The number of elements to sample.

Returns (Array)

Returns the random elements.

Example

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