Empeld
Empeld plugin documentation.
pluginbase.Helpers.Computative.Rand Class Reference

Convenience methods for random number generation More...

Static Public Member Functions

static float Float ()
 Generate a random float between 0 inclusive and 1 exclusive More...
 
static float Float (float max)
 Generate a random float between 0 inclusive and max exclusive More...
 
static float Float (float min, float max)
 Generate a random float between min inclusive and max exclusive More...
 
static double Double ()
 Generate a random double between 0 inclusive and 1 exclusive More...
 
static double Double (double max)
 Generate a double between 0 inclusive and max exclusive More...
 
static double Double (double min, double max)
 Generate a double between min inclusive and max exclusive More...
 
static int Int ()
 Returns a random integer More...
 
static int Int (int max)
 Returns a random integer less than max More...
 
static int Int (int min, int max)
 Returns a random integer greater than min and less than max More...
 
static double Unitd ()
 Returns a random double between 0.0 inclusive, and 1.0 exclusive More...
 
static float Unitf ()
 Return a random float between 0.0 inclusive, and 1.0 exclusive More...
 
static double Dird ()
 Return a double between -1 and 1 More...
 
static float Dirf ()
 Return a float between -1 and 1 More...
 
static Vector3d Dir3d ()
 Return a normalized random vector More...
 
static Vector3d Dirz3d ()
 Return a normalized vector masked with (1,1,0) More...
 
static Vector3 Dir3f ()
 Return a normalized random vector More...
 
static Vector3 Dirz3f ()
 Return a normal vector masked with (1,1,0) More...
 
static Vector3 Vec3f (float min, float max)
 Create a vector where each component is between min and max More...
 
static Vector3d Vec3d (double min, double max)
 Create a vector where each component is between min and max More...
 
static bool Chance (double likelihood)
 Returns true if a random number falls below a likelihood More...
 
static T PickRandom< T > (this IEnumerable< T > items)
 Pick an item randomly from a list More...
 
static T PickRandom< T > (this IList< T > items)
 Pick an item randomly from a list More...
 
static T PickRandomOrNull< T > (this IEnumerable< T > items)
 Pick an item randomly from a list More...
 
static T PickRandomOrNull< T > (this IList< T > items)
 Pick an item randomly from a list More...
 

Detailed Description

Convenience methods for random number generation

Attribute: ThreadSafe

Member Function Documentation

◆ Chance()

static bool pluginbase.Helpers.Computative.Rand.Chance ( double  likelihood)
static

Returns true if a random number falls below a likelihood

Parameters
likelihoodLikelihood.
195  {
196  return RandGen.NextDouble() < likelihood;
197  }

◆ Dir3d()

static Vector3d pluginbase.Helpers.Computative.Rand.Dir3d ( )
static

Return a normalized random vector

140  {
141  return new Vector3d(Dird(), Dird(), Dird()).Normalized();
142  }
static double Dird()
Return a double between -1 and 1
Definition: Rand.cs:123

◆ Dir3f()

static Vector3 pluginbase.Helpers.Computative.Rand.Dir3f ( )
static

Return a normalized random vector

156  {
157  return new Vector3(Dirf(), Dirf(), Dirf()).Normalized();
158  }
static float Dirf()
Return a float between -1 and 1
Definition: Rand.cs:131

◆ Dird()

static double pluginbase.Helpers.Computative.Rand.Dird ( )
static

Return a double between -1 and 1

124  {
125  return RandGen.NextDouble() * 2.0 - 1.0;
126  }

◆ Dirf()

static float pluginbase.Helpers.Computative.Rand.Dirf ( )
static

Return a float between -1 and 1

132  {
133  return (float)RandGen.NextDouble() * 2f - 1f;
134  }

◆ Dirz3d()

static Vector3d pluginbase.Helpers.Computative.Rand.Dirz3d ( )
static

Return a normalized vector masked with (1,1,0)

148  {
149  return new Vector3d(Dird(), Dird(), 0.0).Normalized();
150  }
static double Dird()
Return a double between -1 and 1
Definition: Rand.cs:123

◆ Dirz3f()

static Vector3 pluginbase.Helpers.Computative.Rand.Dirz3f ( )
static

Return a normal vector masked with (1,1,0)

164  {
165  return new Vector3(Dirf(), Dirf(), 0f).Normalized();
166  }
static float Dirf()
Return a float between -1 and 1
Definition: Rand.cs:131

◆ Double() [1/3]

static double pluginbase.Helpers.Computative.Rand.Double ( )
static

Generate a random double between 0 inclusive and 1 exclusive

54  {
55  return RandGen.NextDouble();
56  }

◆ Double() [2/3]

static double pluginbase.Helpers.Computative.Rand.Double ( double  max)
static

Generate a double between 0 inclusive and max exclusive

Parameters
maxMax.
63  {
64  return RandGen.NextDouble() * max;
65  }

◆ Double() [3/3]

static double pluginbase.Helpers.Computative.Rand.Double ( double  min,
double  max 
)
static

Generate a double between min inclusive and max exclusive

Parameters
minMinimum.
maxMax.
73  {
74  return RandGen.NextDouble() * (max - min) + min;
75  }

◆ Float() [1/3]

static float pluginbase.Helpers.Computative.Rand.Float ( )
static

Generate a random float between 0 inclusive and 1 exclusive

27  {
28  return (float)RandGen.NextDouble();
29  }

◆ Float() [2/3]

static float pluginbase.Helpers.Computative.Rand.Float ( float  max)
static

Generate a random float between 0 inclusive and max exclusive

Parameters
maxMax.
36  {
37  return (float)RandGen.NextDouble() * max;
38  }

◆ Float() [3/3]

static float pluginbase.Helpers.Computative.Rand.Float ( float  min,
float  max 
)
static

Generate a random float between min inclusive and max exclusive

Parameters
minMinimum.
maxMax.
46  {
47  return (float)RandGen.NextDouble() * (max - min) + min;
48  }

◆ Int() [1/3]

static int pluginbase.Helpers.Computative.Rand.Int ( )
static

Returns a random integer

81  {
82  return RandGen.Next();
83  }

◆ Int() [2/3]

static int pluginbase.Helpers.Computative.Rand.Int ( int  max)
static

Returns a random integer less than max

Parameters
maxThe exclusive max value.
90  {
91  return RandGen.Next(max);
92  }

◆ Int() [3/3]

static int pluginbase.Helpers.Computative.Rand.Int ( int  min,
int  max 
)
static

Returns a random integer greater than min and less than max

Parameters
minInclusive minimum.
maxExclusive max.
100  {
101  return RandGen.Next(min, max);
102  }

◆ PickRandom< T >() [1/2]

static T pluginbase.Helpers.Computative.Rand.PickRandom< T > ( this IEnumerable< T >  items)
static

Pick an item randomly from a list

Returns
The random.
Parameters
itemsItems.
Template Parameters
TThe 1st type parameter.

Attribute: Rand.Int(arr.Length)

;

206  {
207  var arr = items.ToArray();
208  if (arr.Length == 0)
209  return default(T);
210  return arr[Rand.Int(arr.Length)];
211  }

◆ PickRandom< T >() [2/2]

static T pluginbase.Helpers.Computative.Rand.PickRandom< T > ( this IList< T >  items)
static

Pick an item randomly from a list

Returns
The random.
Parameters
itemsItems.
Template Parameters
TThe 1st type parameter.

Attribute: Rand.Int(items.Count)

;

220  {
221  if (items.Count == 0)
222  return default(T);
223  return items[Rand.Int(items.Count)];
224  }

◆ PickRandomOrNull< T >() [1/2]

static T pluginbase.Helpers.Computative.Rand.PickRandomOrNull< T > ( this IEnumerable< T >  items)
static

Pick an item randomly from a list

Returns
The random.
Parameters
itemsItems.
Template Parameters
TThe 1st type parameter.

Attribute: Rand.Int(arr.Length)

;

Type Constraints
T :struct 
233  : struct
234  {
235  var arr = items.ToArray();
236  if (arr.Length == 0)
237  return null;
238  return arr[Rand.Int(arr.Length)];
239  }

◆ PickRandomOrNull< T >() [2/2]

static T pluginbase.Helpers.Computative.Rand.PickRandomOrNull< T > ( this IList< T >  items)
static

Pick an item randomly from a list

Returns
The random.
Parameters
itemsItems.
Template Parameters
TThe 1st type parameter.

Attribute: Rand.Int(items.Count)

;

Type Constraints
T :struct 
248  : struct
249  {
250  if (items.Count == 0)
251  return null;
252  return items[Rand.Int(items.Count)];
253  }

◆ Unitd()

static double pluginbase.Helpers.Computative.Rand.Unitd ( )
static

Returns a random double between 0.0 inclusive, and 1.0 exclusive

108  {
109  return RandGen.NextDouble();
110  }

◆ Unitf()

static float pluginbase.Helpers.Computative.Rand.Unitf ( )
static

Return a random float between 0.0 inclusive, and 1.0 exclusive

116  {
117  return (float)RandGen.NextDouble();
118  }

◆ Vec3d()

static Vector3d pluginbase.Helpers.Computative.Rand.Vec3d ( double  min,
double  max 
)
static

Create a vector where each component is between min and max

Returns
The vec3d.
Parameters
minMinimum.
maxMax.
186  {
187  return new Vector3d(Double(min, max), Double(min, max), Double(min, max));
188  }
static double Double()
Generate a random double between 0 inclusive and 1 exclusive
Definition: Rand.cs:53

◆ Vec3f()

static Vector3 pluginbase.Helpers.Computative.Rand.Vec3f ( float  min,
float  max 
)
static

Create a vector where each component is between min and max

Returns
The vec3f.
Parameters
minMinimum.
maxMax.
175  {
176  return new Vector3(Float(min, max), Float(min, max), Float(min, max));
177  }
static float Float()
Generate a random float between 0 inclusive and 1 exclusive
Definition: Rand.cs:26

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