Posted By

IsoJon on 07/07/10


Tagged

number random range


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

alptugan
donaldleegraham


Find Random Number in Range


 / Published in: ActionScript 3
 

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.

  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  

You need to login to post a comment.