/// <summary> /// Creates a random <see langword="string"/> value with a length within the specified range using /// the specified distribution algorithm for generating alpha characters. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="minimumLength">The minimum length.</param> /// <param name="maximumLength">The maximum length.</param> /// <param name="distribution">The distribution algorithm to use.</param> /// <returns>A random <see langword="string"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception> public static string AnyString(this IAnonymousData anon, int minimumLength, int maximumLength, Distribution distribution) { Argument.NotNull(anon, nameof(anon)); Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length."); var length = anon.AnyInt32(minimumLength, maximumLength); var builder = new StringBuilder(length); while (builder.Length < length) { builder.Append(anon.AnyAlphaChar(distribution)); } return(builder.ToString()); }
/// <summary> /// Creates an anonymous <see langword="char"/> value within the range of alpha characters using /// a uniform distribution algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <returns>A random alpha character.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> public static char AnyAlphaChar(this IAnonymousData anon) { Argument.NotNull(anon, nameof(anon)); return(anon.AnyAlphaChar(Distribution.Uniform)); }