UnityEssentials
Small but useful tools and features for Unity
|
An easier to use and a feature-rich class to generate pseudo-random results. More...
Public Member Functions | |
RandomEssentials () | |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. More... | |
RandomEssentials (int seed) | |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. More... | |
int | GetRandomInt () |
int | GetRandomInt (int exclusiveMaximum) |
Returns a non-negative random integer that is less than the specified maximum. More... | |
int | GetRandomInt (int inclusiveMinimum, int exclusiveMaximum) |
Returns a random integer that is within a specified range. More... | |
int | GetRandomSign (float negativeProbability=0.5f) |
Returns a random sign as -1 or +1. More... | |
bool | GetRandomBool (float probability=0.5f) |
Returns a random bool. More... | |
bool | GetRandomBoolTrueEnsured (int tryNumberSinceLastPositive, int maxNumberOfTries) |
Returns a random bool that will be true before the maximum number of tries is exceeded. More... | |
bool | GetPseudoRandomDistributedBool (int tryNumberSinceLastPositive, float probability) |
Returns a random bool using pseudo-random distribution. More... | |
float | GetRandomFloat () |
Returns a random float between 0 (included) and 1 (excluded) More... | |
float | GetRandomFloat (float exclusiveMaximum) |
Returns a random float that is less than the specified maximum. More... | |
float | GetRandomFloat (float inclusiveMinimum, float exclusiveMaximum) |
Returns a random float that is within a specified range. More... | |
Vector3 | GetRandomVector3 (float inclusiveMinimum, float exclusiveMaximum) |
Returns a random Vector3 with each parameter within a specified range. More... | |
Vector2 | GetRandomVector2 (float inclusiveMinimum, float exclusiveMaximum) |
Returns a random Vector2 with each parameter within a specified range. More... | |
void | SetRandomBytes (Byte[] bytesArray) |
Fills the elements of a specified array of bytes with random numbers. More... | |
Vector2 | GetPointInsideCircle (Vector2 center, float radius=1f) |
Returns a random point inside a circle. More... | |
Vector2 | GetPointInsideCircle (float radius=1f) |
Returns a random point inside a circle with center (0, 0). More... | |
Vector2 | GetPointOnCircle (Vector2 center, float radius=1f) |
Returns a random point on a circle. More... | |
Vector2 | GetPointOnCircle (float radius=1f) |
Returns a random point inside a circle with center (0, 0). More... | |
Color | GetColorHSV (float hueMin=0.0f, float hueMax=1f, float saturationMin=0.0f, float saturationMax=1f, float valueMin=0.0f, float valueMax=1f, float alphaMin=1f, float alphaMax=1f) |
Static Public Member Functions | |
static RandomEssentials | GetNew () |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. More... | |
static RandomEssentials | GetNew (int seed) |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. More... | |
An easier to use and a feature-rich class to generate pseudo-random results.
Definition at line 8 of file RandomEssentials.cs.
UnityEngine.RandomEssentials.RandomEssentials | ( | ) |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
Initializes pseudo-random number generator using a default seed value.
Definition at line 17 of file RandomEssentials.cs.
UnityEngine.RandomEssentials.RandomEssentials | ( | int | seed | ) |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
Initializes pseudo-random number generator, using the specified seed value.
Using a custom seed ensures that the generated results will be the same (in the same order) all the times the same seed is used.
seed | A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. |
Definition at line 27 of file RandomEssentials.cs.
Color UnityEngine.RandomEssentials.GetColorHSV | ( | float | hueMin = 0.0f , |
float | hueMax = 1f , |
||
float | saturationMin = 0.0f , |
||
float | saturationMax = 1f , |
||
float | valueMin = 0.0f , |
||
float | valueMax = 1f , |
||
float | alphaMin = 1f , |
||
float | alphaMax = 1f |
||
) |
|
static |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
Initializes pseudo-random number generator using a default seed value.
Definition at line 36 of file RandomEssentials.cs.
|
static |
Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
seed | A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. |
Definition at line 46 of file RandomEssentials.cs.
Vector2 UnityEngine.RandomEssentials.GetPointInsideCircle | ( | float | radius = 1f | ) |
Returns a random point inside a circle with center (0, 0).
radius | The radius of the circle. |
Definition at line 262 of file RandomEssentials.cs.
Vector2 UnityEngine.RandomEssentials.GetPointInsideCircle | ( | Vector2 | center, |
float | radius = 1f |
||
) |
Returns a random point inside a circle.
center | The center of the circle. |
radius | The radius of the circle. |
Definition at line 248 of file RandomEssentials.cs.
Vector2 UnityEngine.RandomEssentials.GetPointOnCircle | ( | float | radius = 1f | ) |
Returns a random point inside a circle with center (0, 0).
radius | The radius of the circle. |
Definition at line 287 of file RandomEssentials.cs.
Vector2 UnityEngine.RandomEssentials.GetPointOnCircle | ( | Vector2 | center, |
float | radius = 1f |
||
) |
Returns a random point on a circle.
center | The center of the circle. |
radius | The radius of the circle. |
Definition at line 274 of file RandomEssentials.cs.
bool UnityEngine.RandomEssentials.GetPseudoRandomDistributedBool | ( | int | tryNumberSinceLastPositive, |
float | probability | ||
) |
Returns a random bool using pseudo-random distribution.
The chances of returning a 'true' increases every time it does not occur, but is lower at the first tries.
Be aware that the resulting probability using this method won't be exactly the same as the given as parameter (but it will be approximated).
tryNumberSinceLastPositive | The number of the try since the last true was returned. It must be greater than 0. It should increase by one on each try and be restarted when a true is returned. |
probability | The probability of returning a true. It must be within the range [0, 1] |
Definition at line 133 of file RandomEssentials.cs.
bool UnityEngine.RandomEssentials.GetRandomBool | ( | float | probability = 0.5f | ) |
Returns a random bool.
probability | The probability of returning a true. It must be within the range [0, 1] |
Definition at line 109 of file RandomEssentials.cs.
bool UnityEngine.RandomEssentials.GetRandomBoolTrueEnsured | ( | int | tryNumberSinceLastPositive, |
int | maxNumberOfTries | ||
) |
Returns a random bool that will be true before the maximum number of tries is exceeded.
tryNumberSinceLastPositive | The number of the try since the last true was returned. It must be greater than 0. It should increase by one on each try and be restarted when a true is returned. |
maxNumberOfTries | The maximum number of tries than can be done to ensure a true return. It should be greater than or equal to tryNumberSinceLastPositive. |
Definition at line 120 of file RandomEssentials.cs.
float UnityEngine.RandomEssentials.GetRandomFloat | ( | ) |
Returns a random float between 0 (included) and 1 (excluded)
Definition at line 173 of file RandomEssentials.cs.
float UnityEngine.RandomEssentials.GetRandomFloat | ( | float | exclusiveMaximum | ) |
Returns a random float that is less than the specified maximum.
exclusiveMaximum | The exclusive upper bound of the random number to be generated. It must be greater than or equal to 0. |
Definition at line 183 of file RandomEssentials.cs.
float UnityEngine.RandomEssentials.GetRandomFloat | ( | float | inclusiveMinimum, |
float | exclusiveMaximum | ||
) |
Returns a random float that is within a specified range.
inclusiveMinimum | The inclusive lower bound of the random number returned. |
exclusiveMaximum | The exclusive upper bound of the random number returned. It must be greater than or equal to inclusiveMinimum. |
Definition at line 194 of file RandomEssentials.cs.
int UnityEngine.RandomEssentials.GetRandomInt | ( | ) |
Returns a non-negative random integer between 0 (included) and Int32.MaxValue (excluded).
Int32.MaxValue = 2147483647
Definition at line 60 of file RandomEssentials.cs.
int UnityEngine.RandomEssentials.GetRandomInt | ( | int | exclusiveMaximum | ) |
Returns a non-negative random integer that is less than the specified maximum.
exclusiveMaximum | The exclusive upper bound of the random number to be generated. It must be greater than or equal to 0. |
Definition at line 70 of file RandomEssentials.cs.
int UnityEngine.RandomEssentials.GetRandomInt | ( | int | inclusiveMinimum, |
int | exclusiveMaximum | ||
) |
Returns a random integer that is within a specified range.
inclusiveMinimum | The inclusive lower bound of the random number returned. |
exclusiveMaximum | The exclusive upper bound of the random number returned. It must be greater than or equal to inclusiveMinimum. |
Definition at line 81 of file RandomEssentials.cs.
int UnityEngine.RandomEssentials.GetRandomSign | ( | float | negativeProbability = 0.5f | ) |
Returns a random sign as -1 or +1.
negativeProbability | The probability of returning a -1 instead of a 1. It must be within the range [0, 1] |
Definition at line 95 of file RandomEssentials.cs.
Vector2 UnityEngine.RandomEssentials.GetRandomVector2 | ( | float | inclusiveMinimum, |
float | exclusiveMaximum | ||
) |
Returns a random Vector2 with each parameter within a specified range.
inclusiveMinimum | The inclusive lower bound of each parameter. |
exclusiveMaximum | The exclusive upper bound of each parameter. It must be greater than or equal to inclusiveMinimum. |
Definition at line 220 of file RandomEssentials.cs.
Vector3 UnityEngine.RandomEssentials.GetRandomVector3 | ( | float | inclusiveMinimum, |
float | exclusiveMaximum | ||
) |
Returns a random Vector3 with each parameter within a specified range.
inclusiveMinimum | The inclusive lower bound of each parameter. |
exclusiveMaximum | The exclusive upper bound of each parameter. It must be greater than or equal to inclusiveMinimum. |
Definition at line 209 of file RandomEssentials.cs.
void UnityEngine.RandomEssentials.SetRandomBytes | ( | Byte[] | bytesArray | ) |
Fills the elements of a specified array of bytes with random numbers.
bytesArray | The array to be filled with random numbers. |
Definition at line 233 of file RandomEssentials.cs.