Find Random Number in Range


/ Published in: ActionScript 3
Save to your folder(s)

Always need one of these on hand. Feed it a minimum number and a maximum number and it returns a random within that range. Super useful.


Copy this code and paste it in your HTML
  1. // usage
  2. trace( randRange( 1, 10 ));
  3.  
  4.  
  5. function randRange( minNum:Number, maxNum:Number ) : Number
  6. {
  7. return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.