Custom Asteroids  1.0.0
A mod for Kerbal Space Program that lets users control where asteroids appear
 All Classes Namespaces Files Functions Variables Enumerations Properties Pages
RandomDist Class Reference

Contains static methods for random number distributions. More...

Static Package Functions

static T weightedSample< T > (System.Collections.Generic.IList< Pair< T, double >> weightedChoices)
 Randomly selects from discrete options with unequal weights. More...
 
static double drawSign ()
 Returns +1 or -1 with equal probability. More...
 
static double drawAngle ()
 Returns a value between 0 and 360. More...
 
static double drawUniform (double a, double b)
 Draws a value from a uniform distribution. More...
 
static double drawLogUniform (double a, double b)
 Draws a value from a log-uniform distribution. More...
 
static double drawExponential (double mean)
 Draws a value from an exponential distribution. More...
 
static double drawRayleigh (double mean)
 Draws a value from a Rayleigh distribution. More...
 
static double drawNormal (double mean, double stddev)
 Draws a value from a normal distribution. More...
 
static double drawIsotropic ()
 Draws the inclination of a randomly oriented plane. More...
 

Static Private Attributes

static double nextNormal
 Caches the next normal random variate to return from drawNormal()
 
static bool isNextNormal
 nextNormal is valid if and only if isNextNormal is true
 

Detailed Description

Contains static methods for random number distributions.

Member Function Documentation

static double drawAngle ( )
staticpackage

Returns a value between 0 and 360.

Returns
A uniform random variate over [0, 360]
Exception Safety
Does not throw exceptions.
static double drawExponential ( double  mean)
staticpackage

Draws a value from an exponential distribution.

Parameters
[in]meanThe mean of the distribution.
Returns
An exponential random variate. The return value has the same units as mean
Precondition
mean ≥ 0
Exceptions
System.ArgumentOutOfRangeExceptionThrown if mean < 0
Exception Safety
This method is atomic
static double drawIsotropic ( )
staticpackage

Draws the inclination of a randomly oriented plane.

Returns
An angle between 0° and 180°, weighted by the sine of the angle.
Note
This function is intended to be used with inclinations. Drawing an inclination from this distribution and drawing a longitude of ascending node uniformly from [0°, 360°] will ensure that the orbital normal faces any direction with equal probability
Exception Safety
Does not throw exceptions
static double drawLogUniform ( double  a,
double  b 
)
staticpackage

Draws a value from a log-uniform distribution.

Parameters
[in]a,bThe endpoints of the range containing the random variate.
Returns
A log-uniform random variate in the interval [a, b]. The return value has the same units as a and b.
Precondition
0 < ab
Exceptions
System.ArgumentOutOfRangeExceptionThrown if a > b, or if either a or b is nonpositive
Exception Safety
This method is atomic
static double drawNormal ( double  mean,
double  stddev 
)
staticpackage

Draws a value from a normal distribution.

Parameters
[in]meanThe mean of the distribution.
[in]stddevThe standard deviation of the distribution.
Returns
A normal random variate. The return value has the same units as mean and stddev
Precondition
stddev ≥ 0
Exceptions
System.ArgumentOutOfRangeExceptionThrown if stddev < 0
Exception Safety
This method is atomic
static double drawRayleigh ( double  mean)
staticpackage

Draws a value from a Rayleigh distribution.

Parameters
[in]meanThe mean of the distribution. This is not the standard parametrization of the Rayleigh distribution, but it is easier to pick values for
Returns
A Rayleigh random variate. The return value has the same units as mean
Precondition
mean ≥ 0
Exceptions
System.ArgumentOutOfRangeExceptionThrown if mean < 0
Exception Safety
This method is atomic
static double drawSign ( )
staticpackage

Returns +1 or -1 with equal probability.

Returns
The value +1 or -1.
Exception Safety
Does not throw exceptions.
static double drawUniform ( double  a,
double  b 
)
staticpackage

Draws a value from a uniform distribution.

Parameters
[in]a,bThe endpoints of the range containing the random variate.
Returns
A uniform random variate in the interval [a, b]. The return value has the same units as a and b.
Precondition
ab
Exceptions
System.ArgumentOutOfRangeExceptionThrown if a > b
Exception Safety
This method is atomic
static T weightedSample< T > ( System.Collections.Generic.IList< Pair< T, double >>  weightedChoices)
staticpackage

Randomly selects from discrete options with unequal weights.

Template Parameters
TThe type of object to be selected
Parameters
[in]weightedChoicesA list of (T, double) tuples. The first value of each tuple represents one of the choices, the second the weight for that choice. The odds of selecting two choices equals the ratio of the weights between them.
Returns
The selected object.
Precondition
weightedChoices contains at least one element
For each element x of weightedChoices, x.Second is nonnegative.
There exists an element x of weightedChoices where x.Second is positive.
Postcondition
The return value is in weightedChoices
Exceptions
System.ArgumentExceptionThrown if weightedChoices is empty
System.ArgumentOutOfRangeExceptionThrown if any weight is negative, or if no weight is positive
Exception Safety
The method is atomic.

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