Probability.Select Method

Performs a weighted selection of an element from an array of values.

Namespace: Microsoft.Modeling
Assembly: Microsoft.Xrt.Runtime (in Microsoft.Xrt.Runtime.dll)

Usage

'Usage

Syntax

'Declaration
public static T Select<T> (
    T[] values,
    double[] probabilities
)

GenericParameters

  • T
    The type of elements in the array.

Parameters

  • values
    The array of values.
  • probabilities
    The array of weights.

Return Value

The selected element.

Example

The following example shows a Cord action declaration with embedded code. Each time this action occurs in a behavior, the action will have one parameter, the value of which is chosen from the values 1, 5, 25, and 125.

action abstract static void Adapter.Add(int x)
    where {.
        int[] values = new int[] { 1, 5, 25, 125 };
        double[] probabilities = new double[] { 4.0, 2.0, 1.0, 0.5 };
        Condition.IsTrue(x == Probability.Select(values, probabilities));
    .};

Exceptions

Exception type Condition
ArgumentException

values and probabilities have different lengths, or values and probabilities are empty, or any element in probabilities is less than zero.

NullReferenceException

values or probabilities is null.

Remarks

The chance that this method returns a specific element is proportional to the element's corresponding weighting in probabilities.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Microsoft Windows 7, Microsoft Windows Vista, Microsoft Windows XP SP2 or later, Microsoft Windows Server 2008, Microsoft Windows Server 2003

Change History

See Also

Reference

Probability Class
Probability Members
Microsoft.Modeling Namespace