Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/random-int
Generate a random integer
https://github.com/sindresorhus/random-int
Last synced: 28 days ago
JSON representation
Generate a random integer
- Host: GitHub
- URL: https://github.com/sindresorhus/random-int
- Owner: sindresorhus
- License: mit
- Created: 2015-06-26T22:23:26.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2021-04-17T18:02:19.000Z (over 3 years ago)
- Last Synced: 2024-05-22T19:01:28.049Z (6 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 85
- Watchers: 6
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-frontend - random-int - Generate a random integer. ![](https://img.shields.io/github/stars/sindresorhus/random-int.svg?style=social&label=Star) (Repository / Number)
- awesome-nodejs-cn - random-int - 生成随机整数 (包 / 数字)
- awesome-nodejs - random-int - Generate a random integer. (Repository / Number)
- awesome-nodejs-cn - random-int - **star:85** 生成一个随机整数 (包 / 数量)
- stars - sindresorhus/random-int - Generate a random integer (JavaScript)
- awesome-nodejs - random-int - Generate a random integer. (Packages / Number)
- awesome-nodejs - random-int - Generate a random integer - ★ 40 (Number)
- awesome-node - random-int - Generate a random integer. (Packages / Number)
- awesome-nodejs-cn - random-int - 生成随机整数. (目录 / 数字)
README
# random-int
> Generate a random integer
## Install
```
$ npm install random-int
```## Usage
```js
import randomInteger from 'random-int';randomInteger(5);
//=> 3randomInteger(10, 100);
//=> 54
```## API
### randomInteger(maximum?)
Returns an integer from `0` to `maximum`.
### randomInteger(minimum, maximum)
Returns an integer from `minimum` to `maximum`.
#### minimum
Type: `number`\
Default: `0`Minimum integer to return.
#### maximum
Type: `number`\
Default: `1`Maximum integer to return.
## Related
- [random-float](https://github.com/sindresorhus/random-float) - Generate a random float
- [random-item](https://github.com/sindresorhus/random-item) - Get a random item from an array
- [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object
- [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object
- [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique
- [unique-random-array](https://github.com/sindresorhus/unique-random-array) - Get consecutively unique elements from an array
- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string