BinomialDistribution.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) Returns a single random sample from a binomial distribution with the specified parameters. The probability of a trial resulting in a success is set to 0.5.
Sample(Random, Int32[]) Fills an Int32 array with random numbers.
Obsolete
Sample(IRandomSource, Int32, Double) 
Sample(Random, Int32, Double) Returns a single random sample from a binomial distribution with the specified parameters.
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>(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<TGenerator>(IRandomSource<TGenerator>, Int32, Double) Returns a single random sample from a binomial distribution with the specified parameters.

Sample<TGenerator>(TGenerator)

Returns a random sample from the distribution using the provided generator.
C#
protected override 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(Random, Int32)

Returns a single random sample from a binomial distribution with the specified parameters. The probability of a trial resulting in a success is set to 0.5.
C#
public static int Sample(
	Random random,
	int numberOfTrials
)

Parameters

random  Random
The Random derived random number generator used to generate the sample.
numberOfTrials  Int32
The number of trials.

Return Value

Int32
A 32-bit signed integer sample from the binomial distribution with the specified parameters.

Remarks

This method is useful when only a single random sample is required, or if the parameters of the distribution change often. To obtain a large number of samples from a distribution with identical parameters, create an instance of the class and call the Sample() method repeatedly.

Exceptions

ArgumentNullException

random is null.

ArgumentOutOfRangeException

numberOfTrials is less than zero.

Sample(IRandomSource, Int32, Double)

C#
public static int Sample(
	IRandomSource random,
	int numberOfTrials,
	double probabilityOfSuccess
)

Parameters

random  IRandomSource
 
numberOfTrials  Int32
 
probabilityOfSuccess  Double
 

Return Value

Int32

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

Returns a single random sample from a binomial distribution with the specified parameters.
C#
public static int Sample<TGenerator>(
	IRandomSource<TGenerator> random,
	int numberOfTrials,
	double probabilityOfSuccess = 0.5
)
where TGenerator : struct, new(), IRandomGenerator

Parameters

random  IRandomSource<TGenerator>
The Random derived random number generator used to generate the sample.
numberOfTrials  Int32
The number of trials.
probabilityOfSuccess  Double  (Optional)
The probability of a trial resulting in success.

Type Parameters

TGenerator

Return Value

Int32
A 32-bit signed integer sample from the binomial distribution with the specified parameters.

Remarks

This method is useful when only a single random sample is required, or if the parameters of the distribution change often. To obtain a large number of samples from a distribution with identical parameters, create an instance of the class and call the Sample() method repeatedly.

Exceptions

ArgumentNullException

random is null.

ArgumentOutOfRangeException

numberOfTrials is less than zero.

-or-

probabilityOfSuccess is less than zero or greater than 1.

Sample(Random, Int32, Double)

Returns a single random sample from a binomial distribution with the specified parameters.
C#
public static int Sample(
	Random random,
	int numberOfTrials,
	double probabilityOfSuccess
)

Parameters

random  Random
The Random derived random number generator used to generate the sample.
numberOfTrials  Int32
The number of trials.
probabilityOfSuccess  Double
The probability of a trial resulting in success.

Return Value

Int32
A 32-bit signed integer sample from the binomial distribution with the specified parameters.

Remarks

This method is useful when only a single random sample is required, or if the parameters of the distribution change often. To obtain a large number of samples from a distribution with identical parameters, create an instance of the class and call the Sample() method repeatedly.

Exceptions

ArgumentNullException

random is null.

ArgumentOutOfRangeException

numberOfTrials is less than zero.

-or-

probabilityOfSuccess is less than zero or greater than 1.

See Also