2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-03-25 00:00:00 +00:00
|
|
|
// A unique name generator
|
|
|
|
export class NameGenerator {
|
|
|
|
// List of available choices
|
|
|
|
private choices: string[];
|
|
|
|
|
|
|
|
// Random generator to use
|
|
|
|
private random: RandomGenerator;
|
|
|
|
|
|
|
|
constructor(choices: string[], random: RandomGenerator = new RandomGenerator()) {
|
|
|
|
this.choices = choices.slice(0);
|
|
|
|
this.random = random;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a new unique name from available choices
|
2017-03-09 17:11:00 +00:00
|
|
|
getName(): string | null {
|
2015-03-25 00:00:00 +00:00
|
|
|
if (this.choices.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-02-26 17:44:15 +00:00
|
|
|
var index = this.random.randInt(0, this.choices.length - 1);
|
2015-03-25 00:00:00 +00:00
|
|
|
var result = this.choices[index];
|
|
|
|
this.choices.splice(index, 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|