mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Add support for floating point numbers to _.random. [closes #263]
Former-commit-id: ef356bb180b163fc936ef69ac2ef33186983eaa7
This commit is contained in:
@@ -4961,8 +4961,13 @@
|
||||
if (max == null) {
|
||||
max = min;
|
||||
min = 0;
|
||||
} else {
|
||||
max = +max || 0;
|
||||
}
|
||||
return min + floor(nativeRandom() * ((+max || 0) - min + 1));
|
||||
var rand = nativeRandom();
|
||||
return (min % 1 || max % 1)
|
||||
? min + nativeMin(rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1))), max)
|
||||
: min + floor(rand * (max - min + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user