/// <summary> /// Creates a uniform distribution over strings that start with an upper case letter followed by /// one or more letters, with length within the given bounds. /// If <paramref name="maxLength"/> is set to <see langword="null"/>, /// there will be no upper bound on the length, and the resulting distribution will thus be improper. /// </summary> /// <param name="minLength">The minimum possible string length. Defaults to 2.</param> /// <param name="maxLength"> /// The maximum possible sequence length, or <see langword="null"/> for no upper bound on length. /// Defaults to <see langword="null"/>. /// </param> /// <param name="allowUpperAfterFirst">Whether to allow upper case letters after the initial upper case letter. If false, only lower case letters will be allowed.</param> /// <returns>The created distribution.</returns> public static StringDistribution Capitalized(int minLength = 2, int?maxLength = null, bool allowUpperAfterFirst = false) { Argument.CheckIfInRange(minLength >= 1, "minLength", "The minimum length of a capitalized string should be 1 or more."); Argument.CheckIfValid(!maxLength.HasValue || maxLength.Value >= minLength, "The maximum length cannot be less than the minimum length."); var result = StringDistribution.Char(DiscreteChar.Upper()); if (maxLength.HasValue) { result.AppendInPlace( allowUpperAfterFirst ? StringDistribution.Letters(minLength: minLength - 1, maxLength: maxLength.Value - 1) : StringDistribution.Lower(minLength: minLength - 1, maxLength: maxLength.Value - 1)); } else { // Concatenation with an improper distribution, need to adjust its scale so that the result is 1 on its support double logNormalizer = result.GetLogAverageOf(result); var lowercaseSuffixFunc = (allowUpperAfterFirst ? StringDistribution.Letters(minLength: minLength - 1) : StringDistribution.Lower(minLength: minLength - 1)).GetNormalizedWorkspaceOrPoint(); var lowercaseSuffixFuncScaled = lowercaseSuffixFunc.ScaleLog(-logNormalizer); result.AppendInPlace(StringDistribution.FromWorkspace(lowercaseSuffixFuncScaled)); } return(result); }