sampleSize
最后更新于:2022-04-02 00:00:24
## sampleSize
+ [link](./sampleSize "Link to this entry.")
+ [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8128 "View in source.")
+ [npm](https://www.npmjs.com/package/lodash.samplesize "See the npm package.")
```
_.sampleSize(collection, [n=0])
```
获得从集合中随机获得 `N` 个元素 Gets `n` random elements from `collection`.
### 参数
1. collection (Array|Object)
要取样的集合
2. [n=0] (number)
要取得的元素个数
### 返回值 (Array)
返回随机元素
### 示例
```
_.sampleSize([1, 2, 3], 2);
// => [3, 1]
_.sampleSize([1, 2, 3], 4);
// => [2, 3, 1]
```
';