Matrix.RandomUniform Method

Definition

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

Overload List

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

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

Creates a new matrix with uniform random numbers in the specified range.
C#
public static DenseMatrix<double> RandomUniform(
	int rowCount,
	int columnCount,
	double min,
	double max,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

rowCount  Int32
The number of rows in the new matrix.
columnCount  Int32
The number of columns in the new matrix.
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 matrix's values may be changed. The default is mutable values.

Return Value

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

Example

C#
// Create a 3x4 matrix with values between -1 and 1
var m = Matrix.RandomUniform(3, 4, -1.0, 1.0);

Exceptions

ArgumentOutOfRangeExceptionrowCount or columnCount is less than zero.

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

Creates a new matrix with uniform random numbers in the specified range.
C#
public static DenseMatrix<double> RandomUniform(
	int rowCount,
	int columnCount,
	double min,
	double max,
	Random random,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

rowCount  Int32
The number of rows in the new matrix.
columnCount  Int32
The number of columns in the new matrix.
min  Double
The lower bound of the uniform distribution (inclusive).
max  Double
The upper bound of the uniform distribution (exclusive).
random  Random
A random number generator used to generate samples.
mutability  ArrayMutability  (Optional)
Specifies how the matrix's values may be changed. The default is mutable values.

Return Value

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

Example

C#
// Create a reproducible 3x4 matrix with values between -1 and 1
var rng = new Random(42);
var m = Matrix.RandomUniform(3, 4, -1.0, 1.0, rng);

Exceptions

ArgumentOutOfRangeExceptionrowCount or columnCount is less than zero.
ArgumentNullExceptionrandom is null.

See Also