Hello! There is a counter and the code below works. Now, judging by the line o.update(v++); +1 is added to the current result every second. Is it possible to make an addition to the random range? Those. sometimes adds + 2 at once, and sometimes +3.

A place where there should be a random number commented.

 (function(){ $('.odometer').each(function(){ var v = 100000; var o = new Odometer({ el: this, value: v, format:'', theme: $(this).data('theme') }); o.render(); setInterval(function(){ o.update(v++); // ВОТ ТУТ ДОЛЖНО БЫТЬ РАНДОМНОЕ ЧИСЛО }, 1000); }); })(); 

Thank you in advance.

  • Math.random () returns a number from 0 to 1. - Nazar Kalytiuk

2 answers 2

To do this, usually use the function Math.random () .

 // Рандомное целое от 1 до 10 console.log(Math.floor(1+10*Math.random())); 

 (function(){ $('.odometer').each(function(){ var v = 100000; var o = new Odometer({ el: this, value: v, format:'', theme: $(this).data('theme') }); o.render(); setInterval(function(){ v = v + Math.floor(1+10*Math.random()); o.update(v); }, 1000); }); })(); 
     function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } 
    • please make as detailed answers as possible. - Mikhail Rebrov