/// <summary> /// Creates a random value of the specified <see cref="Enum"/> type using a uniform distribution /// algorithm. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="enumType">The <see cref="Enum"/> type.</param> /// <returns>A random value of the specified <see cref="Enum"/> type.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="enumType"/> is <c>null</c>.</exception> public static object AnyEnumValue(this IAnonymousData anon, Type enumType) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(enumType, nameof(enumType)); Argument.IsEnumType(enumType, nameof(enumType)); return(anon.AnyEnumValue(enumType, Distribution.Uniform)); }
/// <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)); }