No puedo generar una matriz multidimensional y llenarla con valores aleatorios, traté de usar for loops, forEach y map con Math.random, pero todas las matrices son idénticas.
function mat(a=5,b=5,max=2){ let mt = new Array(a).fill( new Array(b).fill(0) ) mt.map( (x,xk)=>{ x.map( (y,yk)=>{ mt[xk][yk] = Math.round( Math.random()*max ) }) }) return mt } console.log(JSON.stringify(mat()))ejemplo de salida
[[0,0,2,2,0], [0,0,2,2,0], [0,0,2,2,0], [0,0,2,2,0], [0,0,2,2,0]]¿¿por qué?? ¡No tiene sentido!