Probability.Choose Method

Performs an unweighted selection of an element from a collection of values.

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

Usage

'Usage

Syntax

'Declaration
public static T Choose<T> (
    IEnumerable<T> domain
)

GenericParameters

  • T
    The type of elements in the collection.

Parameters

  • domain
    The collection of values.

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 };
        Condition.IsTrue(x == Probability.Choose(values));
    .};

Exceptions

Exception type Condition
ArgumentException

domain is empty.

NullReferenceException

domain is null.

Remarks

The distribution of the elements returned by this method is uniform, that is, every element has an equal chance of being returned.

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