/// <summary> /// Returns a random number in range [0,1] from an exponential distribution. /// </summary> /// <returns>Random number in range [0,1] from given exponential distribution.</returns> /// <param name="exponent"> /// Exponent for distribution. Must be >= 0. /// 0 will be uniform distribution; 1 will be linear distribution w/ slope 1. /// </param> /// <param name="direction">The direction for the curve (right/left).</param> public static float RandomFromExponentialDistribution(float exponent, DirectionE direction) { // our curve will go from 0 to 1. var max_cdf = ExponentialRightCdf(1.0f, exponent); var u = Random.Range(0.0f, max_cdf); var x_val = EponentialRightInverseCdf(u, exponent); if (direction == DirectionE.Left_) { x_val = 1.0f - x_val; } return(x_val); }
/// <summary> /// Returns random in range [0,1] from a curved right slope. /// </summary> /// <returns>Random in range [0,1] from a curved right slope.</returns> /// <param name="skew">The difference in height between max and min of curve.</param> public static float RandomFromSlopedDistribution(float skew, DirectionE direction) { // the difference in scale is just the same as the max y-value.. var max_y = skew; // our curve will go from 0 to max_x. var max_x = Inverse_Sec_Sqrd(max_y); var max_cdf = Sec_Sqrd_CumulativeDistribution(max_x); var u = Random.Range(0.0f, max_cdf); var x_val = Sec_Sqrd_InverseCumulativeDistribution(u); // scale to [0,1] var value = x_val / max_x; if (direction == DirectionE.Left_) { value = 1.0f - value; } return(value); }
//-------------------------------------------------------------------------------------------- // Exponential Distribution //-------------------------------------------------------------------------------------------- /// <summary> /// Returns a random number in range [min,max] from an exponential distribution. /// </summary> /// <returns>Random number in range [min,max] from given exponential distribution.</returns> /// <param name="min">Minimum random number (inclusive).</param> /// <param name="max">Maximum random number (inclusive).</param> /// <param name="exponent"> /// Exponent for distribution. Must be >= 0. /// 0 will be uniform distribution; 1 will be linear distribution w/ slope 1. /// </param> /// <param name="direction">The direction for the curve (right/left).</param> public static float RandomRangeExponential(float min, float max, float exponent, DirectionE direction) { return(min + RandomFromExponentialDistribution(exponent, direction) * (max - min)); }
/// <summary> /// Returns a random number in range [min,max] from a curved slope following sec^2(x). /// </summary> /// <returns>Random in range [min,max] from a curved left slope.</returns> /// <param name="skew">The difference in height between max and min of curve.</param> public static float RandomRangeSlope(float min, float max, float skew, DirectionE direction) { return(min + RandomFromSlopedDistribution(skew, direction) * (max - min)); }
public void SetPosition(int positionX, int positionY, DirectionE direction) { PositionX = positionX; Direction = direction; PositionY = positionY; }