ContinuousDistribution.Sample Method

Definition

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

Overload List

Sample() Returns a single random sample drawn from this 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 a Random 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<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 single random sample drawn from this distribution.
C#
public double Sample()

Return Value

Double
A double-precision random variate.

Remarks

This convenience overload uses the thread-safe random source Instance to generate the uniform variate used by the sampling algorithm.

Successive calls produce independent samples that follow the probability law represented by this distribution.

Sample(Int32)

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

Parameters

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

Return Value

Vector<Double>
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 a Random instance.
C#
public double Sample(
	IRandomSource random
)

Parameters

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

Return Value

Double
A double-precision random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample<TGenerator>(IRandomSource<TGenerator>)

Returns a random sample from the distribution using the supplied IRandomSource<TGenerator>.
C#
public double 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

Double
A double-precision random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample(Random)

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

Parameters

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

Return Value

Double
A double-precision random variate.

Exceptions

ArgumentNullExceptionrandom is null.

Sample<TGenerator>(TGenerator)

Returns a random sample from the distribution using the provided generator.
C#
protected virtual double 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

Double
A double-precision 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<double> 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<Double>
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<double> 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<Double>
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<double> 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<Double>
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.

See Also