0

I want to generate a chess board with fixed cols and rows and randomize the number (stand for the status) in it.Here is the code:

function Board(){
  this.board = new Array(10).fill(new Array(10).fill(0));
}
Board.prototype.renew = function(){
  this.board = new Array(10).fill(new Array(10).fill(0));
}
Board.prototype.randomize = function(){
  for(i=0;i<10;i++){
    for(j=0;j<10;j++)this.board[i][j] = Math.floor(Math.random()+0.5);
  }
}

var apple = new Board();

apple.randomize();

console.log(apple.board.join("\n"));

Then I got this:

0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0
0,1,1,0,1,0,0,1,0,0

I didn't expect that it seems to have some regular pattern among rows.I run this several times.Although I get different value inside a row, all rows still share the same pattern.

Philipl
  • 395
  • 4
  • 21

0 Answers0