Increase random variable name length after name collision

This commit is contained in:
sanex3339
2017-07-26 01:52:22 +03:00
parent fdbce57232
commit 6301f1c15d
2 changed files with 11 additions and 8051 deletions
+1 -8047
View File
File diff suppressed because one or more lines are too long
+10 -4
View File
@@ -41,6 +41,11 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
*/
private readonly options: IOptions;
/**
* @type {number}
*/
private randomVariableNameAdditionalLength: number = 0;
/**
* @type {Set<string>}
*/
@@ -89,8 +94,6 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
this.seed = this.options.seed !== 0 ? this.options.seed : getRandomInteger(0, 999999999);
this.randomGenerator = new Chance(getSeed());
console.log(`seed is ${this.seed}`);
}
/**
@@ -151,10 +154,13 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
const rangeMaxInteger: number = 99999999;
const randomInteger: number = this.getRandomInteger(rangeMinInteger, rangeMaxInteger);
const hexadecimalNumber: string = Utils.decToHex(randomInteger);
const randomVariableName: string = `${prefix}${hexadecimalNumber.substr(0, length)}`;
const randomVariableNameLength: number = length + this.randomVariableNameAdditionalLength;
const randomVariableName: string = `${prefix}${hexadecimalNumber.repeat(2).substr(0, randomVariableNameLength)}`;
if (this.randomVariableNameSet.has(randomVariableName)) {
return this.getRandomVariableName(length);
this.randomVariableNameAdditionalLength++;
return this.getRandomVariableName(randomVariableNameLength);
}
this.randomVariableNameSet.add(randomVariableName);