UnityEssentials
Small but useful tools and features for Unity
Public Member Functions | Static Public Member Functions | List of all members
UnityEngine.RandomEssentials Class Reference

An easier to use and a feature-rich class to generate pseudo-random results. More...

Collaboration diagram for UnityEngine.RandomEssentials:
Collaboration graph

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...
 

Detailed Description

An easier to use and a feature-rich class to generate pseudo-random results.

Definition at line 8 of file RandomEssentials.cs.

Constructor & Destructor Documentation

◆ RandomEssentials() [1/2]

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.

Here is the caller graph for this function:

◆ RandomEssentials() [2/2]

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.

Parameters
seedA 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.

Member Function Documentation

◆ GetColorHSV()

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 
)

Definition at line 304 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetNew() [1/2]

static RandomEssentials UnityEngine.RandomEssentials.GetNew ( )
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.

Returns
A new instance a pseudo-random number generator of type "RandomEssentials".

Definition at line 36 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetNew() [2/2]

static RandomEssentials UnityEngine.RandomEssentials.GetNew ( int  seed)
static

Creates a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.

Parameters
seedA 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.
Returns
A new instance a pseudo-random number generator of type "RandomEssentials".

Definition at line 46 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetPointInsideCircle() [1/2]

Vector2 UnityEngine.RandomEssentials.GetPointInsideCircle ( float  radius = 1f)

Returns a random point inside a circle with center (0, 0).

Parameters
radiusThe radius of the circle.
Returns

Definition at line 262 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetPointInsideCircle() [2/2]

Vector2 UnityEngine.RandomEssentials.GetPointInsideCircle ( Vector2  center,
float  radius = 1f 
)

Returns a random point inside a circle.

Parameters
centerThe center of the circle.
radiusThe radius of the circle.
Returns

Definition at line 248 of file RandomEssentials.cs.

Here is the caller graph for this function:

◆ GetPointOnCircle() [1/2]

Vector2 UnityEngine.RandomEssentials.GetPointOnCircle ( float  radius = 1f)

Returns a random point inside a circle with center (0, 0).

Parameters
radiusThe radius of the circle.
Returns

Definition at line 287 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetPointOnCircle() [2/2]

Vector2 UnityEngine.RandomEssentials.GetPointOnCircle ( Vector2  center,
float  radius = 1f 
)

Returns a random point on a circle.

Parameters
centerThe center of the circle.
radiusThe radius of the circle.
Returns

Definition at line 274 of file RandomEssentials.cs.

◆ GetPseudoRandomDistributedBool()

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).

Parameters
tryNumberSinceLastPositiveThe 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.
probabilityThe probability of returning a true. It must be within the range [0, 1]
Returns
A random bool.

Definition at line 133 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetRandomBool()

bool UnityEngine.RandomEssentials.GetRandomBool ( float  probability = 0.5f)

Returns a random bool.

Parameters
probabilityThe probability of returning a true. It must be within the range [0, 1]
Returns
A random true or false

Definition at line 109 of file RandomEssentials.cs.

Here is the caller graph for this function:

◆ GetRandomBoolTrueEnsured()

bool UnityEngine.RandomEssentials.GetRandomBoolTrueEnsured ( int  tryNumberSinceLastPositive,
int  maxNumberOfTries 
)

Returns a random bool that will be true before the maximum number of tries is exceeded.

Parameters
tryNumberSinceLastPositiveThe 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.
maxNumberOfTriesThe maximum number of tries than can be done to ensure a true return. It should be greater than or equal to tryNumberSinceLastPositive.
Returns
A random bool.

Definition at line 120 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetRandomFloat() [1/3]

float UnityEngine.RandomEssentials.GetRandomFloat ( )

Returns a random float between 0 (included) and 1 (excluded)

Returns
Random float in range [0, 1)

Definition at line 173 of file RandomEssentials.cs.

Here is the caller graph for this function:

◆ GetRandomFloat() [2/3]

float UnityEngine.RandomEssentials.GetRandomFloat ( float  exclusiveMaximum)

Returns a random float that is less than the specified maximum.

Parameters
exclusiveMaximumThe exclusive upper bound of the random number to be generated. It must be greater than or equal to 0.
Returns
Random integer in range [0, exclusiveMaximum)

Definition at line 183 of file RandomEssentials.cs.

◆ GetRandomFloat() [3/3]

float UnityEngine.RandomEssentials.GetRandomFloat ( float  inclusiveMinimum,
float  exclusiveMaximum 
)

Returns a random float that is within a specified range.

Parameters
inclusiveMinimumThe inclusive lower bound of the random number returned.
exclusiveMaximumThe exclusive upper bound of the random number returned. It must be greater than or equal to inclusiveMinimum.
Returns
Random float in range [inclusiveMinimum, exclusiveMaximum)

Definition at line 194 of file RandomEssentials.cs.

◆ GetRandomInt() [1/3]

int UnityEngine.RandomEssentials.GetRandomInt ( )

Returns a non-negative random integer between 0 (included) and Int32.MaxValue (excluded).

Int32.MaxValue = 2147483647

Returns
Random integer in range [0, Int32.MaxValue)

Definition at line 60 of file RandomEssentials.cs.

Here is the caller graph for this function:

◆ GetRandomInt() [2/3]

int UnityEngine.RandomEssentials.GetRandomInt ( int  exclusiveMaximum)

Returns a non-negative random integer that is less than the specified maximum.

Parameters
exclusiveMaximumThe exclusive upper bound of the random number to be generated. It must be greater than or equal to 0.
Returns
Random integer in range [0, exclusiveMaximum)

Definition at line 70 of file RandomEssentials.cs.

◆ GetRandomInt() [3/3]

int UnityEngine.RandomEssentials.GetRandomInt ( int  inclusiveMinimum,
int  exclusiveMaximum 
)

Returns a random integer that is within a specified range.

Parameters
inclusiveMinimumThe inclusive lower bound of the random number returned.
exclusiveMaximumThe exclusive upper bound of the random number returned. It must be greater than or equal to inclusiveMinimum.
Returns
Random integer in range [inclusiveMinimum, exclusiveMaximum)

Definition at line 81 of file RandomEssentials.cs.

◆ GetRandomSign()

int UnityEngine.RandomEssentials.GetRandomSign ( float  negativeProbability = 0.5f)

Returns a random sign as -1 or +1.

Parameters
negativeProbabilityThe probability of returning a -1 instead of a 1. It must be within the range [0, 1]
Returns
A random 1 or -1

Definition at line 95 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetRandomVector2()

Vector2 UnityEngine.RandomEssentials.GetRandomVector2 ( float  inclusiveMinimum,
float  exclusiveMaximum 
)

Returns a random Vector2 with each parameter within a specified range.

Parameters
inclusiveMinimumThe inclusive lower bound of each parameter.
exclusiveMaximumThe exclusive upper bound of each parameter. It must be greater than or equal to inclusiveMinimum.
Returns
Random Vector2 with each parameter in range [inclusiveMinimum, exclusiveMaximum)

Definition at line 220 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ GetRandomVector3()

Vector3 UnityEngine.RandomEssentials.GetRandomVector3 ( float  inclusiveMinimum,
float  exclusiveMaximum 
)

Returns a random Vector3 with each parameter within a specified range.

Parameters
inclusiveMinimumThe inclusive lower bound of each parameter.
exclusiveMaximumThe exclusive upper bound of each parameter. It must be greater than or equal to inclusiveMinimum.
Returns
Random Vector3 with each parameter in range [inclusiveMinimum, exclusiveMaximum)

Definition at line 209 of file RandomEssentials.cs.

Here is the call graph for this function:

◆ SetRandomBytes()

void UnityEngine.RandomEssentials.SetRandomBytes ( Byte[]  bytesArray)

Fills the elements of a specified array of bytes with random numbers.

Parameters
bytesArrayThe array to be filled with random numbers.

Definition at line 233 of file RandomEssentials.cs.


The documentation for this class was generated from the following file: