|
@@ -29,11 +29,18 @@ console.log(sum3(5, 10, 100500))
|
|
|
console.log(sum3(5, 10))
|
|
|
|
|
|
// intRandom
|
|
|
+// function intRandom(min, max) {
|
|
|
+// min = min || 0;
|
|
|
+// max = max || 0;
|
|
|
+// let result = Math.random() * (max - min) + min;
|
|
|
+// return Math.round(result)
|
|
|
+// }
|
|
|
function intRandom(min, max) {
|
|
|
- min = min || 0;
|
|
|
- max = max || 0;
|
|
|
- let result = Math.random() * (max - min) + min;
|
|
|
- return Math.round(result)
|
|
|
+ if (max === undefined) {
|
|
|
+ max = min
|
|
|
+ min = 0
|
|
|
+ }
|
|
|
+ return Math.floor(Math.random() * (max - min + 1) + min)
|
|
|
}
|
|
|
console.log(intRandom(2, 15))
|
|
|
console.log(intRandom(-1, -1))
|