Package | org.as3utils |
Class | public class RandomUtil |
Inheritance | RandomUtil ![]() |
Method | Defined By | ||
---|---|---|---|
RandomUtil is a static class and shouldn't be instantiated. | RandomUtil | ||
random(min:Number, max:Number, decimalPlaces:int = 0):Number [static]
Returns a random number between a range. | RandomUtil | ||
randomArray(min:Number, max:Number, length:int, decimalPlaces:int = 0):Array [static]
Returns an array of random numbers that can be repeated. | RandomUtil |
RandomUtil | () | Constructor |
public function RandomUtil()
RandomUtil is a static class and shouldn't be instantiated.
IllegalOperationError — RandomUtil is a static class and shouldn't be instantiated.
|
random | () | method |
public static function random(min:Number, max:Number, decimalPlaces:int = 0):Number
Returns a random number between a range.
Parameters
min:Number — the begin of the range.
| |
max:Number — the end of the range.
| |
decimalPlaces:int (default = 0 ) — the number of decimal places.
|
Number — a random number between the range (min, max).
|
ArgumentError — if the max argument is less than the min argument.
|
import org.as3coreaddendum.utils.RandomUtil; RandomUtil.random(0, 10) // 3 RandomUtil.random(0, 10) // 0 RandomUtil.random(0, 10) // 10 RandomUtil.random(0, 10, 1) // 0.9 RandomUtil.random(0, 10, 1) // 9.6 RandomUtil.random(0, 10, 1) // 5.4 RandomUtil.random(0, 10, 2) // 2.87 RandomUtil.random(0, 10, 3) // 4.602 RandomUtil.random(-13, 11, 1) // -9.8 RandomUtil.random(-13, 11, 1) // -12.9 RandomUtil.random(-13, 11, 1) // 10.6 RandomUtil.random(-1000, 1000, 1) // 273.6 RandomUtil.random(-1000, 1000, 1) // -847.2 RandomUtil.random(-20, -10) // -15
randomArray | () | method |
public static function randomArray(min:Number, max:Number, length:int, decimalPlaces:int = 0):Array
Returns an array of random numbers that can be repeated.
Parameters
min:Number — the begin of the range.
| |
max:Number — the end of the range.
| |
length:int — the length of the array, must be greater than zero.
| |
decimalPlaces:int (default = 0 ) — the number of decimal places.
|
Array — an array of random numbers that can be repeated.
|
ArgumentError — if the length argument is less than zero.
|
import org.as3coreaddendum.utils.RandomUtil; RandomUtil.randomArray(0, 10, 5) // [7,5,3,3,9] RandomUtil.randomArray(0, 10, 5, 1) // [5.6,4.6,8.7,3.5,0.9] RandomUtil.randomArray(10, 20, 5) // [16,10,15,16,16] RandomUtil.randomArray(-10, 10, 5) // [-7,-4,-10,7,-3] RandomUtil.randomArray(-7, 4, 5) // [-2,-7,2,2,3] RandomUtil.randomArray(-7, 4, 5, 2) // [-4.88,-4.98,3.38,-0.3,2.41] RandomUtil.randomArray(-20, -10, 5) // [-15,-14,-18,-13,-15] RandomUtil.randomArray(-1000, 1000, 5, 2) // [146.31,-839.97,-85.05,-525.63,-739.22]