this.randomize = function() { var n = dim * dim; for (var i = 0; i < n * 2; i++) { var a = Math.floor(Math.random() * n); this.swap(a, this.empty); } }