<commit_before>package flixel.util;

/**
 * A class containing a set of functions for randomnly 
 * generating numbers or other random things.
 */
class FlxRandom
{
	/**
	 * The global random number generator seed (for deterministic behavior in recordings and saves).
	 */
	static public var globalSeed:Float;
	/**
	 * Internal helper for <code>FlxRandom.int()</code>
	 */
	static private var intHelper:Int = 0;
	/**
	 * Maximum value returned by <code>FlxRandom.intRanged</code> and <code>FlxRandom.floatRanged</code> by default.
	 */
	static public inline var MAX_RANGE:Int = 0xffffff;
	
	/**
	 * Generates a small random number between 0 and 65535 very quickly
	 * 
	 * Generates a small random number between 0 and 65535 using an extremely fast cyclical generator, 
	 * with an even spread of numbers. After the 65536th call to this function the value resets.
	 * 
	 * @return A pseudo random value between 0 and 65536 inclusive.
	 */
	static public function int():Int
	{
		var result:Int = Std.int(intHelper);
		
		result++;
		result *= 75;
		result %= 65537;
		result--;
		
		intHelper++;
		
		if (intHelper == 65536)
		{
			intHelper = 0;
		}
		
		return result;
	}
	
	/**
	 * Generate a random integer
	 * 
	 * If called without the optional min, max arguments rand() returns a peudo-random integer between 0 and MAX_RANGE.
	 * If you want a random number between 5 and 15, for example, (inclusive) use rand(5, 15)
	 * Parameter order is insignificant, the return will always be between the lowest and highest value.
	 * 
	 * @param 	Min 		The lowest value to return (default: 0)
	 * @param 	Max 		The highest value to return (default: MAX_RANGE)
	 * @param 	Excludes 	An Array of integers that will NOT be returned (default: null)
	 * @return A pseudo-random value between min (or 0) and max (or MAX_RANGE, inclusive)
	 */
	static public function intRanged(?Min:Int, ?Max:Int, ?Excludes:Array<Int>):Int
	{
		if (Min == null)
		{
			Min = 0;
		}
		
		if (Max == null)
		{
			Max = MAX_RANGE;
		}
		
		if (Min == Max)
		{
			return Math.floor(Min);
		}
		
		if (Excludes != null)
		{
			// Sort the exclusion array
			Excludes.sort(FlxMath.numericComparison);
			
			var result:Int;
			
			do {
				if (Min < Max)
				{
					result = Math.floor(Min + (Math.random() * (Max + 1 - Min)));
				}
				else
				{
					result = Math.floor(Max + (Math.random() * (Min + 1 - Max)));
				}
			}
			while (FlxArrayUtil.indexOf(Excludes, result) >= 0);
			
			return result;
		}
		else
		{
			// Reverse check
			if (Min < Max)
			{
				return Math.floor(Min + (Math.random() * (Max + 1 - Min)));
			}
			else
			{
				return Math.floor(Max + (Math.random() * (Min + 1 - Max)));
			}
		}
	}
	
	/**
	 * Generates a random number.  Deterministic, meaning safe
	 * to use if you want to record replays in random environments.
	 * @return	A <code>Number</code> between 0 and 1.
	 */
	inline static public function float():Float
	{
		globalSeed = srand(globalSeed);
		if (globalSeed <= 0) globalSeed += 1;
		return globalSeed;
	}
	
	/**
	 * Generate a random float (number)
	 * 
	 * If called without the optional min, max arguments rand() returns a peudo-random float between 0 and MAX_RANGE().
	 * If you want a random number between 5 and 15, for example, (inclusive) use rand(5, 15)
	 * Parameter order is insignificant, the return will always be between the lowest and highest value.
	 * 
	 * @param 	min 	The lowest value to return (default: 0)
	 * @param 	max 	The highest value to return (default: MAX_RANGE)
	 * @return A pseudo random value between min (or 0) and max (or MAX_RANGE, inclusive)
	 */
	static public function floatRanged(?min:Float, ?max:Float):Float
	{
		if (min == null)
		{
			min = 0;
		}
		
		if (max == null)
		{
			max = MAX_RANGE;
		}
		
		if (min == max)
		{
			return min;
		}
		else if (min < max)
		{
			return min + (Math.random() * (max - min + 1));
		}
		else
		{
			return max + (Math.random() * (min - max + 1));
		}
	}
	
	/**
	 * Generates a random number based on the seed provided.
	 * @param	Seed	A number between 0 and 1, used to generate a predictable random number (very optional).
	 * @return	A <code>Number</code> between 0 and 1.
	 */
	inline static public function srand(Seed:Float):Float
	{<commit_msg>FlxRandom.floatRanged() fix. see issue #595<commit_after>package flixel.util;

/**
 * A class containing a set of functions for randomnly 
 * generating numbers or other random things.
 */
class FlxRandom
{
	/**
	 * The global random number generator seed (for deterministic behavior in recordings and saves).
	 */
	static public var globalSeed:Float;
	/**
	 * Internal helper for <code>FlxRandom.int()</code>
	 */
	static private var intHelper:Int = 0;
	/**
	 * Maximum value returned by <code>FlxRandom.intRanged</code> and <code>FlxRandom.floatRanged</code> by default.
	 */
	static public inline var MAX_RANGE:Int = 0xffffff;
	
	/**
	 * Generates a small random number between 0 and 65535 very quickly
	 * 
	 * Generates a small random number between 0 and 65535 using an extremely fast cyclical generator, 
	 * with an even spread of numbers. After the 65536th call to this function the value resets.
	 * 
	 * @return A pseudo random value between 0 and 65536 inclusive.
	 */
	static public function int():Int
	{
		var result:Int = Std.int(intHelper);
		
		result++;
		result *= 75;
		result %= 65537;
		result--;
		
		intHelper++;
		
		if (intHelper == 65536)
		{
			intHelper = 0;
		}
		
		return result;
	}
	
	/**
	 * Generate a random integer
	 * 
	 * If called without the optional min, max arguments rand() returns a peudo-random integer between 0 and MAX_RANGE.
	 * If you want a random number between 5 and 15, for example, (inclusive) use rand(5, 15)
	 * Parameter order is insignificant, the return will always be between the lowest and highest value.
	 * 
	 * @param 	Min 		The lowest value to return (default: 0)
	 * @param 	Max 		The highest value to return (default: MAX_RANGE)
	 * @param 	Excludes 	An Array of integers that will NOT be returned (default: null)
	 * @return A pseudo-random value between min (or 0) and max (or MAX_RANGE, inclusive)
	 */
	static public function intRanged(?Min:Int, ?Max:Int, ?Excludes:Array<Int>):Int
	{
		if (Min == null)
		{
			Min = 0;
		}
		
		if (Max == null)
		{
			Max = MAX_RANGE;
		}
		
		if (Min == Max)
		{
			return Math.floor(Min);
		}
		
		if (Excludes != null)
		{
			// Sort the exclusion array
			Excludes.sort(FlxMath.numericComparison);
			
			var result:Int;
			
			do {
				if (Min < Max)
				{
					result = Math.floor(Min + (Math.random() * (Max + 1 - Min)));
				}
				else
				{
					result = Math.floor(Max + (Math.random() * (Min + 1 - Max)));
				}
			}
			while (FlxArrayUtil.indexOf(Excludes, result) >= 0);
			
			return result;
		}
		else
		{
			// Reverse check
			if (Min < Max)
			{
				return Math.floor(Min + (Math.random() * (Max + 1 - Min)));
			}
			else
			{
				return Math.floor(Max + (Math.random() * (Min + 1 - Max)));
			}
		}
	}
	
	/**
	 * Generates a random number.  Deterministic, meaning safe
	 * to use if you want to record replays in random environments.
	 * @return	A <code>Number</code> between 0 and 1.
	 */
	inline static public function float():Float
	{
		globalSeed = srand(globalSeed);
		if (globalSeed <= 0) globalSeed += 1;
		return globalSeed;
	}
	
	/**
	 * Generate a random float (number)
	 * 
	 * If called without the optional min, max arguments rand() returns a peudo-random float between 0 and MAX_RANGE().
	 * If you want a random number between 5 and 15, for example, (inclusive) use rand(5, 15)
	 * Parameter order is insignificant, the return will always be between the lowest and highest value.
	 * 
	 * @param 	min 	The lowest value to return (default: 0)
	 * @param 	max 	The highest value to return (default: MAX_RANGE)
	 * @return A pseudo random value between min (or 0) and max (or MAX_RANGE, inclusive)
	 */
	static public function floatRanged(?min:Float, ?max:Float):Float
	{
		if (min == null)
		{
			min = 0;
		}
		
		if (max == null)
		{
			max = MAX_RANGE;
		}
		
		if (min == max)
		{
			return min;
		}
		else if (min < max)
		{
			return min + (Math.random() * (max - min));
		}
		else
		{
			return max + (Math.random() * (min - max));
		}
	}
	
	/**
	 * Generates a random number based on the seed provided.
	 * @param	Seed	A number between 0 and 1, used to generate a predictable random number (very optional).
	 * @return	A <code>Number</code> between 0 and 1.
	 */
	inline static public function srand(Seed:Float):Float
	{
{'fraction_non_alphanumeric': 0.11357763683345079, 'fraction_numerical': 0.01726568005637773, 'mean_word_length': 2.85817852288174, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3360969', 'n_tokens_mistral': 3274, 'n_tokens_neox': 2679, 'n_words': 1004}