Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created August 21, 2021 16:01
Show Gist options
  • Save YonatanKra/e27899e67d44e24961fb68a80bedb070 to your computer and use it in GitHub Desktop.
Save YonatanKra/e27899e67d44e24961fb68a80bedb070 to your computer and use it in GitHub Desktop.
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