/// class OneOf { private possibilities = []; private availablePossibilites; private randomMode : number; public static PURELY_AT_RANDOM : number = 0; public static ROTATING_RANDOM : number = 1; public static CYCLING : number = 2; private cyclingOrder : number = 0; public constructor (randomMode : number, ...poss : Array) { this.randomMode = randomMode; this.possibilities = poss; if (this.randomMode == OneOf.ROTATING_RANDOM) { this.availablePossibilites = this.possibilities.slice(); } } public getOne () { if (this.randomMode == OneOf.PURELY_AT_RANDOM) { return this.possibilities[Math.floor(Math.random() * this.possibilities.length)]; } else if (this.randomMode == OneOf.ROTATING_RANDOM) { if (this.availablePossibilites.length < 1) { this.availablePossibilites = this.possibilities.slice(); } return this.availablePossibilites.splice(Math.floor(Math.random() * this.availablePossibilites.length), 1)[0] } else if (this.randomMode == OneOf.CYCLING) { var r = this.possibilities[this.cyclingOrder++]; if (this.cyclingOrder > this.possibilities.length) { this.cyclingOrder = 0; } return r; } } }