Custom Asteroids  0.2.0
A mod for Kerbal Space Program that lets users control where asteroids appear
 All Classes Namespaces Files Functions 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 drawRayleigh (double mean)
 Draws a value from a Rayleigh distribution. More...
 

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