PDA

View Full Version : Is There Something Similar to PHP's rand(0,255)?


ajwei810192
03-25-2010, 06:51 PM
Hi,

I am trying create a random number here that is between 0 and 255. In PHP, you could do something like rand(0,255), does anyone know what is the syntax in Actionscript?

I do something like this:


var low:Number = 0;
var high:Number = 255;
var num:Number = Math.round(Math.random() * (high - low)) + low;


Is there something simpler?

Thanks for your help.

ASWC
03-25-2010, 07:05 PM
var num:Number = Math.floor(Math.random() * 256);

ajwei810192
03-25-2010, 07:09 PM
Thanks, this did the trick.