lychees's picture
Upload 569 files
87b3b3a
raw
history blame contribute delete
477 Bytes
/**
* @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;
}