/// <summary> /// Main generation method which chooses the algorithm to use for the generation. /// It checks some exceptional situations as well. /// </summary> private string GenerateString(int length) { if (length == 0) { throw new ArgumentException("You can't generate a string of a zero length"); } if (!UseUpperCaseCharacters && !UseLowerCaseCharacters && !UseNumericCharacters && !UseSpecialCharacters) { throw new ArgumentException("There should be at least one character set in use"); } if (!RepeatCharacters && (CurrentGeneralCharacters.Length < length)) { throw new ArgumentException("There is not enough characters to create a string without repeats"); } string result = ""; // This string will contain the result if (PatternDriven) { // Using the pattern to generate a string result = PatternDrivenAlgo(Pattern); } else if (MinUpperCaseCharacters == 0 && MinLowerCaseCharacters == 0 && MinNumericCharacters == 0 && MinSpecialCharacters == 0) { // Using the simpliest algorithm in this case result = SimpleGenerateAlgo(length); } else { // Paying attention to limits result = GenerateAlgoWithLimits(length); } // Support for unique strings // Recursion, but possibility of the stack overflow is low for big strings (> 3 chars). if (UniqueStrings && ExistingStrings.Contains(result)) { return(GenerateString(length)); } AddExistingString(result); // Saving history return(result); }
/// /// True if it's not possible to create similar strings. /// //public bool UniqueStrings; /// /// Adding the string to the history array to support unique string generation. /// public void AddExistingString(string s) { ExistingStrings.Add(s); }