-2

I want to store random numbers between 1 to 25 in a two dimensional array. I want the result like the bellow:

Means storing random numbers in a Array[5][5] by Javascript:

Amit Verma
  • 40,709
  • 21
  • 93
  • 115

1 Answers1

0

You really should be showing what you tried but I guess for the sake of it...

var result = new Array(5);
for(i = 0; i < 5; i++){
 result[i] = new Array(5);
  for(j = 0; j < 5; j++){
    result[i][j] = Math.floor((Math.random()*25) + 1);
  }
}

OP question: the result is repeats elements. But I don't want any repeats. How can it possible ? create an array with # 1-25 shuffle it and then put it in a two dimensional array as shown above. How can I shuffle an array?

Community
  • 1
  • 1
alex436
  • 120
  • 8