Vector.RandomUniform Method

Definition

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

Overload List

RandomUniform(Int32, Double, Double, ArrayMutability) Constructs a new vector with uniform random numbers in the specified range.
RandomUniform(Int32, Double, Double, IRandomSource, 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<TGenerator>(Int32, Double, Double, IRandomSource<TGenerator>, 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

// 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, IRandomSource, 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,
	IRandomSource 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  IRandomSource
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.

Exceptions

ArgumentNullExceptionrandom is null.

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

// 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.

RandomUniform<TGenerator>(Int32, Double, Double, IRandomSource<TGenerator>, ArrayMutability)

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

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  IRandomSource<TGenerator>
The random number generator to use.
mutability  ArrayMutability  (Optional)
Specifies how the vector's values may be changed. The default is mutable values.

Type Parameters

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

Return Value

DenseVector<Double>
A DenseVector<T> with random values uniformly distributed between min and max.

Exceptions

ArgumentNullExceptionrandom is null.

See Also