program for Generating Random Numbers using c - Code

Latest

programs

Friday, October 7, 2011

program for Generating Random Numbers using c


Generating Random Numbers


function randRange(minNum, maxNum, decPl)


{


  trace("random number between"+minNum+" and "+maxNum+ "is");


  if(decp1==undefined)


  decp1=0;


  else


  decp1=decp1;


  var rangeDiff = (maxNum - minNum) * Math.pow(10, decPl) + 1;


  var randVal = Math.random(  ) * rangeDiff;


  randVal = Math.floor(randVal);


  randVal /= Math.pow(10, decPl);


  randVal += minNum;


  return Math.floor(randVal, Math.pow(10, -decPl));


}




trace(randRange(100,250,0));


Output


random number between100 and 250is


244

No comments:

Post a Comment