Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to FlxRandom #1138

Merged
merged 4 commits into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
* FlxGamepad:
* added a connected flag
* fixed a bug that would prevent gamepad buttons from being updated
* FlxRandom: exposed internalSeed as a read-only property
* FlxRandom:
* exposed internalSeed as a read-only property
* removed intRanged() and floatRanged(), int() and float() now provide optional ranges
* FlxArrayUtil: removed randomness-related functions, please use FlxRandom instead

3.3.4
------------------------------
Expand Down
28 changes: 6 additions & 22 deletions flixel/math/FlxRandom.hx
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,16 @@ class FlxRandom
return globalSeed = Std.int(Math.random() * MODULUS);
}

/**
* Returns a pseudorandom number between 0 and 2,147,483,647, inclusive.
*/
public static inline function int():Int
{
return generate();
}

/**
* Returns a pseudorandom number between 0 and 1, inclusive.
*/
public static inline function float():Float
{
return generate() / MODULUS;
}

/**
* Returns a pseudorandom integer between Min and Max, inclusive.
* Will not return a number in the Excludes array, if provided.
* Please note that large Excludes arrays can slow calculations.
*
* @param Min The minimum value that should be returned. 0 by default.
* @param Max The maximum value that should be returned. 2,147,483,647 by default.
* @param Excludes An optional array of values that should not be returned.
* @param Excludes An optional array of values that should not be returned. Optional.
*/
public static function intRanged(Min:Int = 0, Max:Int = MODULUS, ?Excludes:Array<Int>):Int
public static function int(Min:Int = 0, Max:Int = MODULUS, ?Excludes:Array<Int>):Int
{
if (Min == Max)
{
Expand Down Expand Up @@ -173,10 +157,10 @@ class FlxRandom
* Please note that large Excludes arrays can slow calculations.
*
* @param Min The minimum value that should be returned. 0 by default.
* @param Max The maximum value that should be returned. 33,554,429 by default.
* @param Excludes An optional array of values that should not be returned.
* @param Max The maximum value that should be returned. 1 by default.
* @param Excludes An optional array of values that should not be returned. Optional.
*/
public static function floatRanged(Min:Float = 0, Max:Float = 1, ?Excludes:Array<Float>):Float
public static function float(Min:Float = 0, Max:Float = 1, ?Excludes:Array<Float>):Float
{
var result:Float = 0;

Expand Down Expand Up @@ -444,4 +428,4 @@ class FlxRandom
{
return internalSeed = ((internalSeed * MULTIPLIER) % MODULUS) & MODULUS;
}
}
}
30 changes: 0 additions & 30 deletions flixel/util/FlxArrayUtil.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package flixel.util;
import flixel.math.FlxRandom;

/**
* A set of functions for array manipulation.
Expand Down Expand Up @@ -32,35 +31,6 @@ class FlxArrayUtil
}
}

/**
* Deprecated; please use FlxRandom.shuffleArray() instead.
* Shuffles the entries in an array into a new random order.
*
* @param Objects An array to shuffle.
* @param HowManyTimes How many swaps to perform during the shuffle operation. A good rule of thumb is 2-4 times the number of objects in the list.
* @return The newly shuffled array.
*/
@:generic
public static inline function shuffle<T>(Objects:Array<T>, HowManyTimes:Int):Array<T>
{
return FlxRandom.shuffleArray(Objects, HowManyTimes);
}

/**
* Deprecated; please use FlxRandom.getObject() instead.
* Fetch a random entry from the given array from StartIndex to EndIndex.
*
* @param Objects An array from which to select a random entry.
* @param StartIndex Optional index from which to restrict selection. Default value is 0, or the beginning of the array.
* @param EndIndex Optional index at which to restrict selection. Ignored if 0, which is the default value.
* @return The random object that was selected.
*/
@:generic
public static inline function getRandom<T>(Objects:Array<T>, StartIndex:Int = 0, EndIndex:Int = 0):T
{
return FlxRandom.getObject(Objects, StartIndex, EndIndex);
}

/**
* Safely removes an element from an array by swapping it with the last element and calling pop()
* (won't do anything if the element is not in the array). This is a lot faster than regular splice(),
Expand Down