unique-random
Advanced tools
Comparing version 1.0.0 to 2.0.0
'use strict'; | ||
module.exports = function (min, max) { | ||
var prev; | ||
module.exports = (min, max) => { | ||
let prev; | ||
return function rand() { | ||
var num = Math.floor(Math.random() * (max - min + 1) + min); | ||
return prev = num === prev && min !== max ? rand() : num; | ||
const num = Math.floor((Math.random() * (max - min + 1)) + min); | ||
prev = (num === prev && min !== max) ? rand() : num; | ||
return prev; | ||
}; | ||
}; |
{ | ||
"name": "unique-random", | ||
"version": "1.0.0", | ||
"description": "Generate random numbers that are consecutively unique", | ||
"keywords": [ | ||
"unique", | ||
"random", | ||
"rand", | ||
"number", | ||
"single", | ||
"generate", | ||
"non-repeating" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": "sindresorhus/unique-random", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
} | ||
"name": "unique-random", | ||
"version": "2.0.0", | ||
"description": "Generate random numbers that are consecutively unique", | ||
"license": "MIT", | ||
"repository": "sindresorhus/unique-random", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"unique", | ||
"uniq", | ||
"random", | ||
"rand", | ||
"number", | ||
"single", | ||
"generate", | ||
"non-repeating", | ||
"consecutively" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
# unique-random [![Build Status](https://travis-ci.org/sindresorhus/unique-random.svg?branch=master)](https://travis-ci.org/sindresorhus/unique-random) | ||
> Generate random numbers that are consecutively unique. | ||
> Generate random numbers that are consecutively unique | ||
Useful for eg. slideshows where you don't want to have the same slide twice in a row. | ||
Useful for things like slideshows where you don't want to have the same slide twice in a row. | ||
@@ -10,5 +10,5 @@ | ||
```sh | ||
$ npm install --save unique-random | ||
``` | ||
$ npm install unique-random | ||
``` | ||
@@ -19,3 +19,5 @@ | ||
```js | ||
var rand = require('unique-random')(1, 10); | ||
const uniqueRandom = require('unique-random'); | ||
const rand = uniqueRandom(1, 10); | ||
console.log(rand(), rand(), rand()); | ||
@@ -28,9 +30,21 @@ //=> 5 2 6 | ||
### uniqueRandom(*min*, *max*) | ||
### uniqueRandom(min, max) | ||
Returns a function which when called will return a random number that's never the same as the previous number. | ||
Returns a function that when called will return a random number that is never the same as the previous. | ||
## Related | ||
- [unique-random-array](https://github.com/sindresorhus/unique-random-array) - Get consecutively unique elements from an array | ||
- [random-int](https://github.com/sindresorhus/random-int) - Generate a random integer | ||
- [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-at-depth](https://github.com/Aweary/unique-random-at-depth) - This module with an optional depth argument | ||
- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3512
4
9
48
2