Posted By

Jamie on 07/21/10


Tagged

number float random generator function


Versions (?)

Random Number (Float) Generator


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.