L
L
Los Angeles2015-10-02 21:05:10
JavaScript
Los Angeles, 2015-10-02 21:05:10

Why does the console always return 10?

function ramdom(max, min) {
  return Math.floor(Math.random() * (max - min) ) + min;
}

var x = function() {
  var z = ramdom(10,10);
  return console.log(z);
};


setInterval(x, 100);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Petrunkin, 2015-10-02
@cleverpope

The minimum and maximum are the same, so their difference is zero. Adding the minimum gives the result. In order to produce different numbers, you need to supply other input parameters to the user-defined rundom function.

D
Dmitry Kovalsky, 2015-10-02
@dmitryKovalskiy

What should? 257? Math.Random*0 + 10 suddenly = 10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question