Contains static methods for random number distributions.
More...
|
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...
|
|
Contains static methods for random number distributions.
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,b | The 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 <
a
≤ b
- Exceptions
-
System.ArgumentOutOfRangeException | Thrown 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] | mean | The 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.ArgumentOutOfRangeException | Thrown 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,b | The 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
a
≤ b
- Exceptions
-
System.ArgumentOutOfRangeException | Thrown 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
-
T | The type of object to be selected |
- Parameters
-
[in] | weightedChoices | A 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.ArgumentException | Thrown if weightedChoices is empty |
System.ArgumentOutOfRangeException | Thrown 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: