Random Number (Float) Generator


/ Published in: JavaScript
Save to your folder(s)

Simple function to return a decimal value between the minValue and the maxValue.


Copy this code and paste it in your HTML
  1. // Random float between
  2. function randomFloatBetween(minValue,maxValue,precision){
  3. if(typeof(precision) == 'undefined'){
  4. precision = 2;
  5. }
  6. return parseFloat(Math.min(minValue + (Math.random() * (maxValue - minValue)),maxValue).toFixed(precision));
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.