mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Replace one time used variables with their original refs in random.
This commit is contained in:
@@ -5,9 +5,7 @@ import toFinite from './toFinite.js'
|
|||||||
const freeParseFloat = parseFloat
|
const freeParseFloat = parseFloat
|
||||||
|
|
||||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||||
const nativeMin = Math.min
|
|
||||||
const nativeRandom = Math.random
|
const nativeRandom = Math.random
|
||||||
const nativeFloor = Math.floor
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produces a random number between the inclusive `lower` and `upper` bounds.
|
* Produces a random number between the inclusive `lower` and `upper` bounds.
|
||||||
@@ -74,9 +72,9 @@ function random(lower, upper, floating) {
|
|||||||
if (floating || lower % 1 || upper % 1) {
|
if (floating || lower % 1 || upper % 1) {
|
||||||
const rand = nativeRandom()
|
const rand = nativeRandom()
|
||||||
const randLength = `${ rand }`.length - 1
|
const randLength = `${ rand }`.length - 1
|
||||||
return nativeMin(lower + (rand * (upper - lower + freeParseFloat(`1e-${ randLength }`)), upper))
|
return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${ randLength }`)), upper))
|
||||||
}
|
}
|
||||||
return lower + nativeFloor(nativeRandom() * (upper - lower + 1))
|
return lower + Math.floor(nativeRandom() * (upper - lower + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
export default random
|
export default random
|
||||||
|
|||||||
Reference in New Issue
Block a user