Random.int(from:Int, to_inclusive:Int):Int Returns an Integer between 'from' and 'to_inclusive'. |
Random.float(from:Int, to_inclusive:Int):Float Returns a Float between 'from' and 'to_inclusive'. |
Random.string(length:Int, ?characters:String):String Returns a random String of a given length. You can optionally specify which characters to use, otherwise the default is (a-zA-Z0-9). |
Random.random():Float Returns an Float between 0 and 1. |
Random.bool():Bool 50:50 chance of being true/false |
Random.chance(n:Float):Bool n% chance (out of 100%) of being true. |
Random.pick(list:Array Picks a random element from an array. import haxegon.*; class Main { function new(){ var temparray:Array< Any> = ["cat", "dog", 47, -0.52, false]; Debug.log("Randomly choosing " + Random.pick(temparray) + " from " + temparray); } } |
Random.shuffle(list:Array Shuffles an array and returns it. import haxegon.*; class Main { function new(){ var temparray:Array< String> = ["cat", "dog", "pig", "rabbit", "frog"]; Debug.log("Original order is: " + temparray); Random.shuffle(temparray); Debug.log("After shuffling: " + temparray); } } |
Random.seed:Int The current seed. Set to an integer of your choosing for a predicable sequence of results. import haxegon.*; class Main { function new(){ Random.seed = 10; Debug.log(Random.int(0, 10)); Debug.log(Random.string(5)); Debug.log(Random.bool()); Debug.log("Seed is " + Random.seed + ", so this sequence is always 8, bLDAc, true"); } } |