dimanche 11 novembre 2018

Set a minimum value for randomly generated numbers

I am using this function to generate and alternate random values inside a div

var change_price = $('#myprice');

animationTimer = setInterval(function() {
        change_price.text( ''+   Math.floor(Math.random() * 100) );
   
}, 1000);
#myprice {
    padding: 20px;
    font-size:24px;
    color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myprice">50</div>

What I want to do is to control the min value too. For example, to have random generated values from 50 to 100.




Aucun commentaire:

Enregistrer un commentaire