DiscreteDistribution.Sample Method

Definition

Namespace: Numerics.NET.Statistics.Distributions
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0

Overload List

Sample() Returns a random sample from the distribution.
Sample(Int32) Returns a vector containing the specified number of independent random samples drawn from this distribution.
Sample(IRandomSource) Returns a random sample from the distribution using an IRandomSource instance.
Sample(Random) Returns a random sample from the distribution using a Random instance.
Sample(Int32, IRandomSource) Returns a vector containing the specified number of independent random samples drawn from this distribution using the provided IRandomSource.
Sample(Int32, Random) Returns a vector of random samples from the distribution.
Sample(IRandomSource, Int32[]) Fills an Int32 array with random numbers.
Obsolete
Sample(Random, Int32[]) Fills an Int32 array with random numbers.
Obsolete
Sample(IRandomSource, Int32[], Int32, Int32) Fills an Int32 array with random numbers from this DiscreteDistribution.
Obsolete
Sample(Random, Int32[], Int32, Int32) Fills an Int32 array with random numbers from this DiscreteDistribution.
Obsolete
Sample<TGenerator>(IRandomSource<TGenerator>) Returns a random sample from the distribution using the supplied IRandomSource<TGenerator>.
Sample<TGenerator>(TGenerator) Returns a random sample from the distribution using the provided generator.
Sample<TGenerator>(Int32, IRandomSource<TGenerator>) Returns a vector containing the specified number of independent random samples drawn from this distribution using the supplied IRandomSource<TGenerator>.

Sample

Returns a random sample from the distribution.
C#
public int Sample()

Return Value

Int32
A signed 32-bit integer.

Remarks

This method uses the default random number generator specified by Instance to generate a random sample from the distribution. The return values of successive calls to this method follow the statistical distribution represented by this distribution.

Sample(Int32)

Returns a vector containing the specified number of independent random samples drawn from this distribution.
C#
public Vector<int> Sample(
	int size
)

Parameters

size  Int32
The number of samples to generate. Must be greater than zero.

Return Value

Vector<Int32>
A Vector<T> of length size.

Remarks

This overload uses Instance as the source of randomness.

Exceptions

ArgumentOutOfRangeExceptionsize is less than or equal to zero.

Sample(IRandomSource)

Returns a random sample from the distribution using an IRandomSource instance.
C#
public int Sample(
	IRandomSource random
)

Parameters

random  IRandomSource
An IRandomSource that will be adapted to the internal generator abstraction.

Return Value

Int32
A signed 32-bit integer random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample<TGenerator>(IRandomSource<TGenerator>)

Returns a random sample from the distribution using the supplied IRandomSource<TGenerator>.
C#
public int Sample<TGenerator>(
	IRandomSource<TGenerator> random
)
where TGenerator : struct, new(), IRandomGenerator

Parameters

random  IRandomSource<TGenerator>
The random source that exposes a IRandomGenerator used to produce uniform variates.

Type Parameters

TGenerator
The underlying generator type of the random source, used to enable optimizations like inlining.

Return Value

Int32
A signed 32-bit integer random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample(Random)

Returns a random sample from the distribution using a Random instance.
C#
public int Sample(
	Random random
)

Parameters

random  Random
A Random that will be adapted to the internal generator abstraction.

Return Value

Int32
A signed 32-bit integer random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample<TGenerator>(TGenerator)

Returns a random sample from the distribution using the provided generator.
C#
protected virtual int Sample<TGenerator>(
	ref TGenerator generator
)
where TGenerator : struct, new(), IRandomGenerator

Parameters

generator  TGenerator
A reference to a struct implementing IRandomGenerator used to produce uniform variates.

Type Parameters

TGenerator
The underlying generator type of the random source, used to enable optimizations like inlining.

Return Value

Int32
A signed 32-bit integer random variate.

Remarks

Implementations may override this method to provide a more efficient or specialized sampling algorithm that consumes raw uniform variates from generator.

Sample(Int32, IRandomSource)

Returns a vector containing the specified number of independent random samples drawn from this distribution using the provided IRandomSource.
C#
public Vector<int> Sample(
	int size,
	IRandomSource random
)

Parameters

size  Int32
The number of samples to generate. Must be greater than zero.
random  IRandomSource
The random source to use for generating uniform variates.

Return Value

Vector<Int32>
A Vector<T> of length size.

Remarks

This overload uses the provided random instance to obtain an internal generator suitable for bulk sampling.

Exceptions

ArgumentNullExceptionrandom is null.
ArgumentOutOfRangeExceptionsize is less than or equal to zero.

Sample(Int32, Random)

Returns a vector of random samples from the distribution.
C#
public Vector<int> Sample(
	int size,
	Random random
)

Parameters

size  Int32
The number of samples to return.
random  Random
A Random object that specifies the uniform random number generator that is to be used to generate the samples.

Return Value

Vector<Int32>
A vector of size samples from the distribution.

Remarks

This method uses the random number generator specified by random to generate a random sample from the distribution. The return values of successive calls to this method follow the distribution represented by this Distribution.

Exceptions

ArgumentNullException

random is null.

ArgumentOutOfRangeException

size is less than zero.

Sample<TGenerator>(Int32, IRandomSource<TGenerator>)

Returns a vector containing the specified number of independent random samples drawn from this distribution using the supplied IRandomSource<TGenerator>.
C#
public Vector<int> Sample<TGenerator>(
	int size,
	IRandomSource<TGenerator> random
)
where TGenerator : struct, new(), IRandomGenerator

Parameters

size  Int32
The number of samples to generate. Must be greater than zero.
random  IRandomSource<TGenerator>
The random source that exposes a TGenerator generator.

Type Parameters

TGenerator
The underlying generator type of the random source, used to enable optimizations like inlining.

Return Value

Vector<Int32>
A Vector<T> containing size samples.

Remarks

This overload avoids extra allocations by obtaining a reference to the underlying generator and forwarding to a ref-based implementation.

Exceptions

ArgumentNullExceptionrandom is null.
ArgumentOutOfRangeExceptionsize is less than or equal to zero.

Sample(IRandomSource, Int32[])

Note: This API is now obsolete.
Fills an Int32 array with random numbers.
C#
[ObsoleteAttribute("Use the SampleInto method with Span<int> instead.")]
public void Sample(
	IRandomSource random,
	int[] samples
)

Parameters

random  IRandomSource
A Random object that specifies the uniform random number generator that is to be used to generate the samples.
samples  Int32[]
A Int32 array.

Remarks

This method fills the integer array samples with random samples from the distribution.

Exceptions

ArgumentNullException

random is null.

-or-

samples is null.

Sample(Random, Int32[])

Note: This API is now obsolete.
Fills an Int32 array with random numbers.
C#
[ObsoleteAttribute("Use the SampleInto method with Span<int> instead.")]
public void Sample(
	Random random,
	int[] samples
)

Parameters

random  Random
A Random object that specifies the uniform random number generator that is to be used to generate the samples.
samples  Int32[]
A Int32 array.

Remarks

This method fills the integer array samples with random samples from the distribution.

Exceptions

ArgumentNullException

random is null.

-or-

samples is null.

Sample(IRandomSource, Int32[], Int32, Int32)

Note: This API is now obsolete.
Fills an Int32 array with random numbers from this DiscreteDistribution.
C#
[ObsoleteAttribute("Use the SampleInto method with Span<int> instead.")]
public void Sample(
	IRandomSource random,
	int[] samples,
	int startIndex,
	int length
)

Parameters

random  IRandomSource
A IRandomSource object that specifies the uniform random number generator that is to be used to generate the samples.
samples  Int32[]
A Int32 array.
startIndex  Int32
The zero-based index at which to begin filling the samples array.
length  Int32
The number of samples to provide.

Remarks

This method fills a block of length elements of samples, starting at index startIndex with random samples from the distribution.

Exceptions

ArgumentNullException

samples is null.

-or-

random is null.

ArgumentOutOfRangeException

startIndex is less than zero.

-or-

length is less than zero.

ArgumentException

length is greater than the number of elements from startIndex to the end of samples.

Sample(Random, Int32[], Int32, Int32)

Note: This API is now obsolete.
Fills an Int32 array with random numbers from this DiscreteDistribution.
C#
[ObsoleteAttribute("Use the SampleInto method with Span<int> instead.")]
public void Sample(
	Random random,
	int[] samples,
	int startIndex,
	int length
)

Parameters

random  Random
A Random object that specifies the uniform random number generator that is to be used to generate the samples.
samples  Int32[]
A Int32 array.
startIndex  Int32
The zero-based index at which to begin filling the samples array.
length  Int32
The number of samples to provide.

Remarks

This method fills a block of length elements of samples, starting at index startIndex with random samples from the distribution.

Exceptions

ArgumentNullException

samples is null.

-or-

random is null.

ArgumentOutOfRangeException

startIndex is less than zero.

-or-

length is less than zero.

ArgumentException

length is greater than the number of elements from startIndex to the end of samples.

See Also