Spaces:
Running
Running
/** | |
* @returns {any} Randomly picked item, null when length=0 | |
*/ | |
Array.prototype.random = function() { | |
if (!this.length) { return null; } | |
return this[Math.floor(ROT.RNG.getUniform() * this.length)]; | |
} | |
/** | |
* @returns {array} New array with randomized items | |
* FIXME destroys this! | |
*/ | |
Array.prototype.randomize = function() { | |
var result = []; | |
while (this.length) { | |
var index = this.indexOf(this.random()); | |
result.push(this.splice(index, 1)[0]); | |
} | |
return result; | |
} | |