/// <summary> /// Creates a random <see langword="int"/> value within the specified range using a uniform distribution algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="minimum">The minimum value.</param> /// <param name="maximum">The maximum value.</param> /// <returns>A random <see langword="int"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception> public static int AnyInt32(this IAnonymousData anon, int minimum, int maximum) { Argument.NotNull(anon, nameof(anon)); Argument.InRange(maximum, minimum, int.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value."); return(anon.AnyInt32(minimum, maximum, Distribution.Uniform)); }
/// <summary> /// Returns a random item from the specified collection. /// </summary> /// <typeparam name="T">The item type.</typeparam> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="collection">The collection.</param> /// <returns>A random item from the collection.</returns> public static T AnyItem <T>(this IAnonymousData anon, IEnumerable <T> collection) { var items = collection as IList <T> ?? collection.ToList(); var index = anon.AnyInt32(0, items.Count); return(items[index]); }
/// <summary> /// Creates a random <see langword="DateTimeOffset"/> value within the specified range using the specified /// distribution algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="minimum">The minimum value.</param> /// <param name="maximum">The maximum value.</param> /// <param name="distribution">The distribution algorithm to use.</param> /// <returns>A random <see langword="DateTimeOffset"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception> public static DateTimeOffset AnyDateTimeOffset(this IAnonymousData anon, DateTimeOffset minimum, DateTimeOffset maximum, Distribution distribution) { Argument.NotNull(anon, nameof(anon)); Argument.InRange(maximum, minimum, DateTimeOffset.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value."); var ticks = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution); var offset = Offsets[anon.AnyInt32(0, Offsets.Length)]; return(new DateTimeOffset(ticks, offset)); }
/// <summary> /// Creates a random <see langword="IEnumerable"/> sequence of objects of the specified type. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="type">The type of objects to create.</param> /// <param name="minimumLength">The minimum length of the sequence.</param> /// <param name="maximumLength">The maximum length of the sequence.</param> /// <returns>A random <see langword="IEnumerable"/> sequence of the specified type of objects.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception> public static IEnumerable AnyEnumerable(this IAnonymousData anon, Type type, int minimumLength, int maximumLength) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(type, nameof(type)); Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length."); int length = anon.AnyInt32(minimumLength, maximumLength); return(AnyEnumerable(anon, type, length)); }
/// <summary> /// Creates a random value of the specified <see cref="Enum"/> type using the specified distribution /// algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="enumType">The <see cref="Enum"/> type.</param> /// <param name="distribution">The distribution algorithm to use.</param> /// <returns>A random value of the specified <see cref="Enum"/> type.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/>, <paramref name="enumType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="enumType"/> is not an enum type.</exception> public static object AnyEnumValue(this IAnonymousData anon, Type enumType, Distribution distribution) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(enumType, nameof(enumType)); Argument.IsEnumType(enumType, nameof(enumType)); var values = Enum.GetValues(enumType); var index = anon.AnyInt32(0, values.Length, distribution); return(values.GetValue(index)); }
private static string AnySimpleFullName(this IAnonymousData anon, bool male) { switch (anon.AnyInt32(0, 5)) { case 0: return($"{anon.AnyFirstName(male)} {anon.AnyFirstName(male).Substring(0, 1)}. {anon.AnySurname()}"); default: return($"{anon.AnyFirstName(male)} {anon.AnySurname()}"); } }
/// <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 a random <see langword="string"/> value representing a full name. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="male">If set to <c>true</c> a male full name is created; otherwise, a female /// full name is created.</param> /// <returns>A random full name.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> public static string AnyFullName(this IAnonymousData anon, bool male) { Argument.NotNull(anon, nameof(anon)); var prefixes = male ? MalePrefixes : FemalPrefixes; switch (anon.AnyInt32(0, 10)) { case 0: return($"{anon.AnyItem(prefixes)} {anon.AnySimpleFullName(male)}"); case 1: return($"{anon.AnySimpleFullName(male)} {anon.AnyItem(Suffixes)}"); case 2: return($"{anon.AnySimpleFullName(male)} {anon.AnyItem(GenerationalSuffixes)}"); default: return(anon.AnySimpleFullName(male)); } }
/// <summary> /// Creates a random positive <see langword="int"/> value. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <returns>A random positive <see langword="int"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> /// <remarks> /// This method may return a zero value, which strictly makes this "any non-negative" from a mathematical /// perspective, but the term "positive" is used because this is what many would expect. /// </remarks> public static int AnyPositiveInt32(this IAnonymousData anon) { Argument.NotNull(anon, nameof(anon)); return(anon.AnyInt32(0, int.MaxValue, Distribution.Uniform)); }
/// <summary> /// Creates a random <see langword="int"/> value using the specified distribution algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="distribution">The distribution algorithm to use.</param> /// <returns>A random <see langword="int"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> public static int AnyInt32(this IAnonymousData anon, Distribution distribution) { Argument.NotNull(anon, nameof(anon)); return(anon.AnyInt32(int.MinValue, int.MaxValue, distribution)); }
/// <summary> /// Creates a random positive <see langword="int"/> value. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <returns>A random positive <see langword="int"/> value.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception> public static int AnyNegativeInt32(this IAnonymousData anon) { Argument.NotNull(anon, nameof(anon)); return(anon.AnyInt32(int.MinValue, -1, Distribution.Uniform)); }
public static Column AnyColumn(this IAnonymousData anon) => new Column(anon.AnyInt32(1, int.MaxValue));
public static Line AnyLine(this IAnonymousData anon) => new Line(anon.AnyInt32(1, int.MaxValue));