Posted By

Activetuts on 01/13/11


Tagged


Versions (?)

Who likes this?

19 people have marked this snippet as a favorite

mitien
chus
PLyczkowski
elbjoern
EderChrono
toxin20
leadingmannigel
danhett
ichnoweb
kure69
AndrewPotter
JaaQ
im3der
elderhsouza
retsub79
makeyko
fifkie
timr
flashdeveloper


Random Number Between Two Values


 / Published in: ActionScript 3
 

URL: http://enva.to/e4ig6z

Generating a random number is often useful when developing applications in AS3 (more so when developing games). AS3 has a built in random number method as a part of it's Math class which generates a number less than 1 and greater than or equal to 0. We can use this to create a useful function for generating a random number between two other numbers.

  1. function random(min:Number, max:Number):Number
  2. {
  3. return min + Math.random() * (max - min);
  4. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chrisaiv on April 7, 2011

Awesome! If you're looking for an awesome suite of Utilities. The Casa Library (CasaLib.org) rocks! For example, they offer your example NumberUtil.randomIntegerWithinRange( minimum, maxium ) as well as many variations such as finding an average, rounding up/down, etc. http://as3.casalib.org/docs/index.html?http://as3.casalib.org/docs/package-orgcasalibmath.html#Classes

You need to login to post a comment.