Hexagon
Loading...
Searching...
No Matches
Hexagon.HexRandom Class Reference

Static Public Member Functions

static T GetRandomElement< T > (this IList< T > collection)
 Returns random element from the given collection with the scope of [first, last].
 
static T GetRandomElementWithIndex< T > (this IList< T > collection, out int index)
 Returns random element from the given collection with the scope of [first, last].
 
static T Select< T > (params T[] values)
 A convenient shorthand to select one of the provided values at random.
 
static IEnumerable< T > GetElements< T > (this IList< T > collection, int num, bool unique=true)
 Takes a specified number of elements from a collection.
 
static void Shuffle< T > (this IList< T > list)
 Shuffles the specified list in place using the Fisher-Yates algorithm.
 
static List< T > GetShuffled< T > (this IList< T > list)
 Returns a new list with the elements of the original list shuffled. The original list remains unchanged.
 
static List< T > GetRandomSubcollection< T > (this IList< T > collection, int minLength, int maxLength)
 Returns a random subcollection of a random length [min, max) from the given collection.
 
static bool GetBool (float trueBias, float falseBias)
 Returns random boolean based on true/false ratio. When they are equal (i.e. 1:1) results are uniformly spread. The larger the bias towards one value is, the more frequent it will appear in the output. No checks for non-zero denominator are performed.
 
static bool GetBool (float minTrue=0.5f)
 Returns random boolean based on the true threshold. The lower it is the more frequent true will appear in output.
 
static int GetSign (float minPositive=0.5f)
 If random [0-1] > 'minPositive' then +1 is returned, otherwise -1. The less 'minPositive' value is the higher the chance of getting +1 is.
 
static int GetTernarSign ()
 Returns either -1, 0 or +1 with uniform distribution among the three.
 
static int GetTernarSign (float negBias, float zeroBias, float posBias)
 Returns random ternar sign (-1/0/1) based on true/false ratio. When they are equal (i.e. 1:1) results are uniformly spread. The larger the bias towards one value is, the more frequent it will appear in the output. No checks for non-zero denominator are performed.
 
static Vector2 GetVector2D ()
 Generates a random Vector2 with values between -1 and 1.
 
static Vector2 GetVector2D (float min, float max)
 Generates a random Vector2 with values between min and max.
 
static Vector2 GetVector2D (Vector2 min, Vector2 max)
 Generates a random Vector2 with values between min and max.
 
static Vector3 GetVector3D ()
 Generates a random Vector3 with values between -1 and 1.
 
static Vector3 GetVector3D (float min, float max)
 Generates a random Vector3 with values between min and max.
 
static Vector3 GetVector3D (Vector3 min, Vector3 max)
 Generates a random Vector3 with values between min and max.
 
static Vector4 GetVector4D ()
 Generates a random Vector4 with values between -1 and 1.
 
static Vector4 GetVector4D (float min, float max)
 Generates a random Vector4 with values between min and max.
 
static Vector4 GetVector4D (Vector4 min, Vector4 max)
 Generates a random Vector4 with values between min and max.
 
static Vector2Int GetVector2Int (int min, int max)
 Generates a random Vector2Int with values between min (inclusive) and max (exclusive).
 
static Vector2Int GetVector2Int (Vector2Int min, Vector2Int max)
 Generates a random Vector2Int with values between min (inclusive) and max (exclusive).
 
static Vector3Int GetVector3Int (int min, int max)
 Generates a random Vector3Int with values between min (inclusive) and max (exclusive).
 
static Vector3Int GetVector3Int (Vector3Int min, Vector3Int max)
 Generates a random Vector3Int with values between min (inclusive) and max (exclusive).
 
static int GetWeightedIndex (float[] segments, float sum)
 Returns index of a segment which a random value fell into. Random value is generated [0-sum]. Larger segments naturally have higher result frequency than smaller ones. Used for controlled randomness ratios.
 
static int GetWeightedIndex (float[] segments)
 Returns index of a segment which a random value fell into. Random value is generated [0-sum]. Sum is calculated automatically. Larger segments naturally have higher result frequency than smaller ones. Used for controlled randomness ratios.
 
static Color GetColorRGBOpaque ()
 
static Color GetColorRGB ()
 
static Color GetColorRGB (float min=0.5f, float max=0.9f)
 
static Color GetColorHSV ()
 
static Color GetColorHSV (float hueMin, float hueMax)
 
static Color GetColorHSV (float hueMin, float hueMax, float saturationMin, float saturationMax)
 
static Color GetColorHSV (float hueMin, float hueMax, float saturationMin, float saturationMax, float valueMin, float valueMax)
 
static Color GetColorHSV (float hueMin, float hueMax, float saturationMin, float saturationMax, float valueMin, float valueMax, float alphaMin, float alphaMax)
 
static Color GetColorHSV (Color minColor, Color maxColor, bool invertHueRange=false)
 Returns a random color between two colors in HSV space. Hue is overflown if hueMax overflows over the end of [0 - 1] range (is less than hueMin).
 
static Vector3 GetPointOnSphere (float radius)
 
static Vector3 GetPointInSphere (float radius)
 
static Vector2 GetPointOnCircle (float radius, float maxAngle=2 *Mathf.PI)
 
static Vector2 GetPointInCircle (float radius, float maxAngle=2 *Mathf.PI)
 
static Vector3 GetPointInBounds (this Bounds bounds)
 
static Vector2 GetPointInRect (this Rect rect)
 
static Quaternion GetRotation2D ()
 
static T GetEnumValue< T > ()
 
static char GetRandomChar (this string str)
 Gets a random character from the given string.
 
static string GetRandomSubstring (this string str)
 Gets a random substring of a random length from the given string.
 
static string GetRandomSubstringOfLength (this string str, int length)
 Gets a random substring of a specified length from the given string.
 
static string GetRandomSubstringOfLength (this string str, int minLength, int maxLength)
 Gets a random substring of a specified length from the given string.
 
static float GetOverflownValue (float rangeMin, float rangeMax, float start, float end)
 Returns a random value between min and max, but if max is less than min, it will overflow the value into the range [rangeMin - rangeMax].
 

Member Function Documentation

◆ GetBool() [1/2]

static bool Hexagon.HexRandom.GetBool ( float minTrue = 0::5f)
inlinestatic

Returns random boolean based on the true threshold. The lower it is the more frequent true will appear in output.

◆ GetBool() [2/2]

static bool Hexagon.HexRandom.GetBool ( float trueBias,
float falseBias )
inlinestatic

Returns random boolean based on true/false ratio. When they are equal (i.e. 1:1) results are uniformly spread. The larger the bias towards one value is, the more frequent it will appear in the output. No checks for non-zero denominator are performed.

◆ GetColorHSV() [1/6]

static Color Hexagon.HexRandom.GetColorHSV ( )
inlinestatic

◆ GetColorHSV() [2/6]

static Color Hexagon.HexRandom.GetColorHSV ( Color minColor,
Color maxColor,
bool invertHueRange = false )
inlinestatic

Returns a random color between two colors in HSV space. Hue is overflown if hueMax overflows over the end of [0 - 1] range (is less than hueMin).

Parameters
minColorMin color
maxColorMax color
invertHueRangeIf set to true, hue range (min and max) will be inverted.
Returns

◆ GetColorHSV() [3/6]

static Color Hexagon.HexRandom.GetColorHSV ( float hueMin,
float hueMax )
inlinestatic

◆ GetColorHSV() [4/6]

static Color Hexagon.HexRandom.GetColorHSV ( float hueMin,
float hueMax,
float saturationMin,
float saturationMax )
inlinestatic

◆ GetColorHSV() [5/6]

static Color Hexagon.HexRandom.GetColorHSV ( float hueMin,
float hueMax,
float saturationMin,
float saturationMax,
float valueMin,
float valueMax )
inlinestatic

◆ GetColorHSV() [6/6]

static Color Hexagon.HexRandom.GetColorHSV ( float hueMin,
float hueMax,
float saturationMin,
float saturationMax,
float valueMin,
float valueMax,
float alphaMin,
float alphaMax )
inlinestatic

◆ GetColorRGB() [1/2]

static Color Hexagon.HexRandom.GetColorRGB ( )
static

◆ GetColorRGB() [2/2]

static Color Hexagon.HexRandom.GetColorRGB ( float min = 0.5f,
float max = 0.9f )
static

◆ GetColorRGBOpaque()

static Color Hexagon.HexRandom.GetColorRGBOpaque ( )
static

◆ GetElements< T >()

static IEnumerable< T > Hexagon.HexRandom.GetElements< T > ( this IList< T > collection,
int num,
bool unique = true )
inlinestatic

Takes a specified number of elements from a collection.

Parameters
collectionThe collection to take from.
numThe number of elements to take.
uniqueIf true, all returned elements will be unique. If false, elements can be chosen more than once.
Returns
An IEnumerable containing the chosen elements.

◆ GetEnumValue< T >()

static T Hexagon.HexRandom.GetEnumValue< T > ( )
inlinestatic
Type Constraints
T :System.Enum 

◆ GetOverflownValue()

static float Hexagon.HexRandom.GetOverflownValue ( float rangeMin,
float rangeMax,
float start,
float end )
inlinestatic

Returns a random value between min and max, but if max is less than min, it will overflow the value into the range [rangeMin - rangeMax].

Parameters
rangeMinMin allowed value
rangeMaxMax allowed value
startRandom range start
endRandom range end
Returns
Value either in range [start - end] if end is equal to or larger than start, or in range [start - rangeMax] U [rangeMin - end] otherwise.

◆ GetPointInBounds()

static Vector3 Hexagon.HexRandom.GetPointInBounds ( this Bounds bounds)
inlinestatic

◆ GetPointInCircle()

static Vector2 Hexagon.HexRandom.GetPointInCircle ( float radius,
float maxAngle = 2 * Mathf::PI )
inlinestatic

◆ GetPointInRect()

static Vector2 Hexagon.HexRandom.GetPointInRect ( this Rect rect)
inlinestatic

◆ GetPointInSphere()

static Vector3 Hexagon.HexRandom.GetPointInSphere ( float radius)
static

◆ GetPointOnCircle()

static Vector2 Hexagon.HexRandom.GetPointOnCircle ( float radius,
float maxAngle = 2 * Mathf::PI )
inlinestatic

◆ GetPointOnSphere()

static Vector3 Hexagon.HexRandom.GetPointOnSphere ( float radius)
static

◆ GetRandomChar()

static char Hexagon.HexRandom.GetRandomChar ( this string str)
inlinestatic

Gets a random character from the given string.

◆ GetRandomElement< T >()

static T Hexagon.HexRandom.GetRandomElement< T > ( this IList< T > collection)
inlinestatic

Returns random element from the given collection with the scope of [first, last].

◆ GetRandomElementWithIndex< T >()

static T Hexagon.HexRandom.GetRandomElementWithIndex< T > ( this IList< T > collection,
out int index )
inlinestatic

Returns random element from the given collection with the scope of [first, last].

◆ GetRandomSubcollection< T >()

static List< T > Hexagon.HexRandom.GetRandomSubcollection< T > ( this IList< T > collection,
int minLength,
int maxLength )
inlinestatic

Returns a random subcollection of a random length [min, max) from the given collection.

Template Parameters
TItem type
Parameters
collectionInput collection
minLengthMin length (inclusive)
maxLengthMax length (exclusive)
Returns

◆ GetRandomSubstring()

static string Hexagon.HexRandom.GetRandomSubstring ( this string str)
inlinestatic

Gets a random substring of a random length from the given string.

◆ GetRandomSubstringOfLength() [1/2]

static string Hexagon.HexRandom.GetRandomSubstringOfLength ( this string str,
int length )
inlinestatic

Gets a random substring of a specified length from the given string.

◆ GetRandomSubstringOfLength() [2/2]

static string Hexagon.HexRandom.GetRandomSubstringOfLength ( this string str,
int minLength,
int maxLength )
inlinestatic

Gets a random substring of a specified length from the given string.

◆ GetRotation2D()

static Quaternion Hexagon.HexRandom.GetRotation2D ( )
static

◆ GetShuffled< T >()

static List< T > Hexagon.HexRandom.GetShuffled< T > ( this IList< T > list)
inlinestatic

Returns a new list with the elements of the original list shuffled. The original list remains unchanged.

Template Parameters
T
Parameters
list
Returns

◆ GetSign()

static int Hexagon.HexRandom.GetSign ( float minPositive = 0::5f)
inlinestatic

If random [0-1] > 'minPositive' then +1 is returned, otherwise -1. The less 'minPositive' value is the higher the chance of getting +1 is.

Parameters
minPositive[0-1] float threshold value, above which will be returned +1
Returns
+1 or -1

◆ GetTernarSign() [1/2]

static int Hexagon.HexRandom.GetTernarSign ( )
inlinestatic

Returns either -1, 0 or +1 with uniform distribution among the three.

Returns

◆ GetTernarSign() [2/2]

static int Hexagon.HexRandom.GetTernarSign ( float negBias,
float zeroBias,
float posBias )
inlinestatic

Returns random ternar sign (-1/0/1) based on true/false ratio. When they are equal (i.e. 1:1) results are uniformly spread. The larger the bias towards one value is, the more frequent it will appear in the output. No checks for non-zero denominator are performed.

Parameters
negBias
zeroBias
posBias
Returns

◆ GetVector2D() [1/3]

static Vector2 Hexagon.HexRandom.GetVector2D ( )
static

Generates a random Vector2 with values between -1 and 1.

◆ GetVector2D() [2/3]

static Vector2 Hexagon.HexRandom.GetVector2D ( float min,
float max )
static

Generates a random Vector2 with values between min and max.

◆ GetVector2D() [3/3]

static Vector2 Hexagon.HexRandom.GetVector2D ( Vector2 min,
Vector2 max )
static

Generates a random Vector2 with values between min and max.

◆ GetVector2Int() [1/2]

static Vector2Int Hexagon.HexRandom.GetVector2Int ( int min,
int max )
static

Generates a random Vector2Int with values between min (inclusive) and max (exclusive).

◆ GetVector2Int() [2/2]

static Vector2Int Hexagon.HexRandom.GetVector2Int ( Vector2Int min,
Vector2Int max )
static

Generates a random Vector2Int with values between min (inclusive) and max (exclusive).

◆ GetVector3D() [1/3]

static Vector3 Hexagon.HexRandom.GetVector3D ( )
static

Generates a random Vector3 with values between -1 and 1.

◆ GetVector3D() [2/3]

static Vector3 Hexagon.HexRandom.GetVector3D ( float min,
float max )
static

Generates a random Vector3 with values between min and max.

◆ GetVector3D() [3/3]

static Vector3 Hexagon.HexRandom.GetVector3D ( Vector3 min,
Vector3 max )
static

Generates a random Vector3 with values between min and max.

◆ GetVector3Int() [1/2]

static Vector3Int Hexagon.HexRandom.GetVector3Int ( int min,
int max )
static

Generates a random Vector3Int with values between min (inclusive) and max (exclusive).

◆ GetVector3Int() [2/2]

static Vector3Int Hexagon.HexRandom.GetVector3Int ( Vector3Int min,
Vector3Int max )
static

Generates a random Vector3Int with values between min (inclusive) and max (exclusive).

◆ GetVector4D() [1/3]

static Vector4 Hexagon.HexRandom.GetVector4D ( )
static

Generates a random Vector4 with values between -1 and 1.

◆ GetVector4D() [2/3]

static Vector4 Hexagon.HexRandom.GetVector4D ( float min,
float max )
static

Generates a random Vector4 with values between min and max.

◆ GetVector4D() [3/3]

static Vector4 Hexagon.HexRandom.GetVector4D ( Vector4 min,
Vector4 max )
static

Generates a random Vector4 with values between min and max.

◆ GetWeightedIndex() [1/2]

static int Hexagon.HexRandom.GetWeightedIndex ( float[] segments)
inlinestatic

Returns index of a segment which a random value fell into. Random value is generated [0-sum]. Sum is calculated automatically. Larger segments naturally have higher result frequency than smaller ones. Used for controlled randomness ratios.

◆ GetWeightedIndex() [2/2]

static int Hexagon.HexRandom.GetWeightedIndex ( float[] segments,
float sum )
inlinestatic

Returns index of a segment which a random value fell into. Random value is generated [0-sum]. Larger segments naturally have higher result frequency than smaller ones. Used for controlled randomness ratios.

◆ Select< T >()

static T Hexagon.HexRandom.Select< T > ( params T[] values)
inlinestatic

A convenient shorthand to select one of the provided values at random.

var chosenColor = HexRandom.Select(Color.red, Color.blue, Color.green);

◆ Shuffle< T >()

static void Hexagon.HexRandom.Shuffle< T > ( this IList< T > list)
inlinestatic

Shuffles the specified list in place using the Fisher-Yates algorithm.


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