Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const N = 2;
const RANDOM_INITIAL_RANGE = 10;
const MATRIX_LENGTH = Math.pow(2, N) + 1;
function randomInRange(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function generateeMatrix() {
const matrix = new Array(MATRIX_LENGTH)
.fill(0)
.map(() => new Array(MATRIX_LENGTH).fill(null));
matrix[0][MATRIX_LENGTH - 1] = randomInRange(0, RANDOM_INITIAL_RANGE);
matrix[MATRIX_LENGTH - 1][0] = randomInRange(0, RANDOM_INITIAL_RANGE);
matrix[0][0] = randomInRange(0, RANDOM_INITIAL_RANGE);
matrix[MATRIX_LENGTH - 1][MATRIX_LENGTH - 1] = randomInRange(
0,
RANDOM_INITIAL_RANGE
);
return matrix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment