Vector.RandomUniform Method

Definition

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

Overload List

RandomUniform(Int32, Double, Double, ArrayMutability) Constructs a new vector with uniform random numbers in the specified range.
RandomUniform(Int32, Double, Double, Random, ArrayMutability) Constructs a new vector with uniform random numbers in the specified range.

RandomUniform(Int32, Double, Double, ArrayMutability)

Constructs a new vector with uniform random numbers in the specified range.
C#
public static DenseVector<double> RandomUniform(
	int length,
	double min,
	double max,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
min  Double
The lower bound of the uniform distribution (inclusive).
max  Double
The upper bound of the uniform distribution (exclusive).
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 uniformly distributed between min and max.

Example

C#
// Create a vector with 10 values between -1 and 1
var v = Vector.RandomUniform(10, -1.0, 1.0);

Exceptions

ArgumentOutOfRangeExceptionlength is less than zero.

RandomUniform(Int32, Double, Double, Random, ArrayMutability)

Constructs a new vector with uniform random numbers in the specified range.
C#
public static DenseVector<double> RandomUniform(
	int length,
	double min,
	double max,
	Random random,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

length  Int32
The length of the vector.
min  Double
The lower bound of the uniform distribution (inclusive).
max  Double
The upper bound of the uniform distribution (exclusive).
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 uniformly distributed between min and max.

Example

C#
// Create a reproducible vector with 10 values between -1 and 1
var rng = new Random(42);
var v = Vector.RandomUniform(10, -1.0, 1.0, rng);

Exceptions

ArgumentOutOfRangeExceptionlength is less than zero.
ArgumentNullExceptionrandom is null.

See Also