Matrix.Random Uniform Method
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
Overload List
| Random | Creates a new matrix with uniform random numbers in the specified range. |
| Random | Creates a new matrix with uniform random numbers in the specified range. |
| Random | Creates a new matrix with uniform random numbers in the specified range. |
| Random | 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.
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
// Create a 3x4 matrix with values between -1 and 1
var m = Matrix.RandomUniform(3, 4, -1.0, 1.0);
Exceptions
| Argument | rowCount or columnCount is less than zero. |
RandomUniform(Int32, Int32, Double, Double, IRandomSource, ArrayMutability)
Creates a new matrix with uniform random numbers in the specified range.
public static DenseMatrix<double> RandomUniform(
int rowCount,
int columnCount,
double min,
double max,
IRandomSource 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 IRandomSource
- 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
// Create a 3x4 matrix with values between -1 and 1
var rng = ThreadSafeRandomSource.Current;
var m = Matrix.RandomUniform(3, 4, -1.0, 1.0, rng);
Exceptions
| Argument | rowCount or columnCount is less than zero. |
| Argument | random is null. |
RandomUniform(Int32, Int32, Double, Double, Random, ArrayMutability)
Creates a new matrix with uniform random numbers in the specified range.
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
// 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
| Argument | rowCount or columnCount is less than zero. |
| Argument | random is null. |
RandomUniform<TGenerator>(Int32, Int32, Double, Double, IRandomSource<TGenerator>, ArrayMutability)
Creates a new matrix with uniform random numbers in the specified range.
public static DenseMatrix<double> RandomUniform<TGenerator>(
int rowCount,
int columnCount,
double min,
double max,
IRandomSource<TGenerator> random,
ArrayMutability mutability = ArrayMutability.MutableValues
)
where TGenerator : struct, new(), IRandomGenerator
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 IRandomSource<TGenerator>
- The random number generator to use.
- mutability ArrayMutability (Optional)
- Specifies how the matrix'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
DenseMatrix<Double>A new DenseMatrix<T> with random values uniformly distributed between min and max.
Exceptions
| Argument | rowCount or columnCount is less than zero. |
| Argument | random is null. |