Skip to content

Commit

Permalink
feat: add maxValue option to Matrix.randInt
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Aug 23, 2016
1 parent f52e4fd commit e5a8541
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/abstractMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function abstractMatrix(superCtor) {
* Creates a matrix with the given dimensions. Values will be randomly set.
* @param {number} rows - Number of rows
* @param {number} columns - Number of columns
* @param {function} [rng] - Random number generator (default: Math.random)
* @param {function} [rng=Math.random] - Random number generator
* @returns {Matrix} The new matrix
*/
static rand(rows, columns, rng) {
Expand All @@ -123,18 +123,20 @@ function abstractMatrix(superCtor) {
}

/**
* Creates a matrix with the given dimensions. Values will be randomly set.
* Creates a matrix with the given dimensions. Values will be random integers.
* @param {number} rows - Number of rows
* @param {number} columns - Number of columns
* @param {function} [rng] - Random number generator (default: Math.random)
* @param {number} [maxValue=1000] - Maximum value
* @param {function} [rng=Math.random] - Random number generator
* @returns {Matrix} The new matrix
*/
static randInt(rows, columns, rng) {
static randInt(rows, columns, maxValue, rng) {
if (maxValue === undefined) maxValue = 1000;
if (rng === undefined) rng = Math.random;
var matrix = this.empty(rows, columns);
for (var i = 0; i < rows; i++) {
for (var j = 0; j < columns; j++) {
var value = parseInt(rng()*1000);
var value = Math.floor(rng() * maxValue);
matrix.set(i, j, value);
}
}
Expand Down Expand Up @@ -1740,4 +1742,4 @@ function abstractMatrix(superCtor) {
}

return Matrix;
}
}

0 comments on commit e5a8541

Please sign in to comment.