Vector.RandomNormal Method

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0

Overload List

RandomNormal(Int32, ArrayMutability) Constructs a new vector with normal random numbers with zero mean and unit standard deviation.
RandomNormal(Int32, Random, ArrayMutability) Constructs a new vector with normal random numbers with zero mean and unit standard deviation.
RandomNormal(Int32, Double, Double, ArrayMutability) Constructs a new vector with normally distributed random numbers.
RandomNormal(Int32, Double, Double, Random, ArrayMutability) Constructs a new vector with normally distributed random numbers.

RandomNormal(Int32, ArrayMutability)

Constructs a new vector with normal random numbers with zero mean and unit standard deviation.
C#
public static DenseVector<double> RandomNormal(
	int length,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
mutability  ArrayMutability  (Optional)
Specifies how the vector's values may be changed. The default is mutable values.

Return Value

DenseVector<Double>
A DenseVector<T>.

RandomNormal(Int32, Random, ArrayMutability)

Constructs a new vector with normal random numbers with zero mean and unit standard deviation.
C#
public static DenseVector<double> RandomNormal(
	int length,
	Random random,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
random  Random
The random number generator to use.
mutability  ArrayMutability  (Optional)
Specifies how the vector's values may be changed. The default is mutable values.

Return Value

DenseVector<Double>
A DenseVector<T>.

RandomNormal(Int32, Double, Double, ArrayMutability)

Constructs a new vector with normally distributed random numbers.
C#
public static DenseVector<double> RandomNormal(
	int length,
	double mean,
	double standardDeviation,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
mean  Double
The mean of the normal distribution.
standardDeviation  Double
The standard deviation of the normal distribution.
mutability  ArrayMutability  (Optional)
Specifies how the vector's values may be changed. The default is mutable values.

Return Value

DenseVector<Double>
A DenseVector<T> with random values from a normal distribution with the specified mean and standard deviation.

Example

C#
// Create a vector with 10 values from N(5, 2)
var v = Vector.RandomNormal(10, 5.0, 2.0);

Exceptions

ArgumentOutOfRangeExceptionlength is less than zero, or standardDeviation is less than or equal to zero.

RandomNormal(Int32, Double, Double, Random, ArrayMutability)

Constructs a new vector with normally distributed random numbers.
C#
public static DenseVector<double> RandomNormal(
	int length,
	double mean,
	double standardDeviation,
	Random random,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
mean  Double
The mean of the normal distribution.
standardDeviation  Double
The standard deviation of the normal distribution.
random  Random
The random number generator to use.
mutability  ArrayMutability  (Optional)
Specifies how the vector's values may be changed. The default is mutable values.

Return Value

DenseVector<Double>
A DenseVector<T> with random values from a normal distribution with the specified mean and standard deviation.

Example

C#
// Create a reproducible vector with 10 values from N(5, 2)
var rng = new Random(42);
var v = Vector.RandomNormal(10, 5.0, 2.0, rng);

Exceptions

ArgumentOutOfRangeExceptionlength is less than zero, or standardDeviation is less than or equal to zero.
ArgumentNullExceptionrandom is null.

See Also