Get random value in range

 To get a random value, say from 17 plus or minus 3, I can say: 


      20 - Math.random() * 6


I was saying:


     d = Math.random() * 3;

     if (Math.random() < 0.5) {

         d *= -1;

     }

     v = 17 + d;


There are more tips at: bbingo.xyz/techtips/

Comments

Popular posts from this blog

webkit-tap-highlight-color in CSS

Steve Jobs quotes