Table of Contents

Class MathematicalCalculator

Namespace
CodeBase
Assembly
4Experience.CodeBase.Core.Runtime.dll

A helper class contains many independent and small methods with various mathematical functions. Mathematical functions mainly related to probability and randomization (System.Random and Unity Random).

public static class MathematicalCalculator
Inheritance
MathematicalCalculator

Constructors

MathematicalCalculator()

The static constructor initializes the randomization system based on System.Random.

private static MathematicalCalculator()

Properties

CurrentSystemRandom

private static Random CurrentSystemRandom { get; set; }

Property Value

Random

Methods

GetInvertMultiplier(bool)

Returns -1 if isInvert equals true and 1 if isInvert equals false.

public static int GetInvertMultiplier(bool isInvert)

Parameters

isInvert bool

Returns

int

GetNormalizedProbability()

Returns a normalized random float number between 0.0 and 1.0. Based on Unity Random.

public static float GetNormalizedProbability()

Returns

float

IsProbabilityLargerThanNormalizedValue(float)

Get random number if drawn number is greater than value return true. Value and drawn number are normalized.

public static bool IsProbabilityLargerThanNormalizedValue(float normalizedValue)

Parameters

normalizedValue float

Returns

bool

IsProbabilityLargerThanValue(float, float, float)

Get random number between minValue and maxValue. If drawn number is greater than value return true.

public static bool IsProbabilityLargerThanValue(float value, float minValue, float maxValue)

Parameters

value float
minValue float
maxValue float

Returns

bool

IsSumEven(int, int)

Returns true if the sum of two numbers is even.

public static bool IsSumEven(int x, int y)

Parameters

x int
y int

Returns

bool

SetAllRandomGeneratorsSeed(int)

Sets one seed for Unity Random and System.Random. The seed is responsible for the initialization of the engine that generates random numbers. For the same seed, the random results will be the same each time with the same drawing conditions.

public static void SetAllRandomGeneratorsSeed(int seed)

Parameters

seed int

SetSystemRandomSeed(int)

Sets the seed for System.Random. The seed is responsible for the initialization of the engine that generates random numbers. For the same seed, the random results will be the same each time with the same drawing conditions.

public static void SetSystemRandomSeed(int seed)

Parameters

seed int

SetUnityRandomSeed(int)

Sets the seed for Unity Random. The seed is responsible for the initialization of the engine that generates random numbers. For the same seed, the random results will be the same each time with the same drawing conditions.

public static void SetUnityRandomSeed(int seed)

Parameters

seed int

SystemRandom(int, int)

Returns a random integer number between min [inclusive] and max [exclusive].

public static int SystemRandom(int min, int max)

Parameters

min int
max int

Returns

int

SystemRandom(float, float)

Returns a random float number between and min [inclusive] and max [exclusive].

public static float SystemRandom(float min, float max)

Parameters

min float
max float

Returns

float

SystemRandom(Vector2)

Returns a random float number between and min [inclusive] and max [exclusive].

public static float SystemRandom(Vector2 range)

Parameters

range Vector2

Returns

float

UnityRandom(int, int)

Returns a random integer number between min [inclusive] and max [exclusive].

public static int UnityRandom(int min, int max)

Parameters

min int
max int

Returns

int

UnityRandom(float, float)

Returns a random float number between and min [inclusive] and max [inclusive].

public static float UnityRandom(float min, float max)

Parameters

min float
max float

Returns

float

UnityRandom(Vector2)

Returns a random float number between and min [inclusive] and max [inclusive].

public static float UnityRandom(Vector2 range)

Parameters

range Vector2

Returns

float