unique-random
Advanced tools
Comparing version 2.0.0 to 2.1.0
15
index.js
'use strict'; | ||
module.exports = (min, max) => { | ||
let prev; | ||
return function rand() { | ||
const num = Math.floor((Math.random() * (max - min + 1)) + min); | ||
prev = (num === prev && min !== max) ? rand() : num; | ||
return prev; | ||
module.exports = (minimum, maximum) => { | ||
let previousValue; | ||
return function random() { | ||
const number = Math.floor( | ||
(Math.random() * (maximum - minimum + 1)) + minimum | ||
); | ||
previousValue = number === previousValue && minimum !== maximum ? random() : number; | ||
return previousValue; | ||
}; | ||
}; |
{ | ||
"name": "unique-random", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Generate random numbers that are consecutively unique", | ||
@@ -16,12 +16,11 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"unique", | ||
"uniq", | ||
"random", | ||
"rand", | ||
"number", | ||
@@ -34,5 +33,6 @@ "single", | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -19,5 +19,6 @@ # unique-random [![Build Status](https://travis-ci.org/sindresorhus/unique-random.svg?branch=master)](https://travis-ci.org/sindresorhus/unique-random) | ||
const uniqueRandom = require('unique-random'); | ||
const rand = uniqueRandom(1, 10); | ||
console.log(rand(), rand(), rand()); | ||
const random = uniqueRandom(1, 10); | ||
console.log(random(), random(), random()); | ||
//=> 5 2 6 | ||
@@ -29,5 +30,5 @@ ``` | ||
### uniqueRandom(min, max) | ||
### uniqueRandom(minimum, maximum) | ||
Returns a function that when called will return a random number that is never the same as the previous. | ||
Returns a function, that when called, will return a random number that is never the same as the previous. | ||
@@ -34,0 +35,0 @@ |
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
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
4082
5
27
49
0
3