/// <summary> /// Generates an Italian Fiscal Code /// </summary> /// <param name="lastName">Last name of the holder</param> /// <param name="firstName">First name of the holder</param> /// <param name="birthday">Birthday of the holder</param> /// <param name="validChecksum"> /// Indicates whether the generated Fiscal Code has a valid checksum or not /// </param> /// <returns>The generated Fiscal Code</returns> /// <remarks>Description of the Fiscal Code standard is at https://en.wikipedia.org/wiki/Italian_fiscal_code_card</remarks> public static string FiscalCode(string lastName, string firstName, DateTime birthday, bool validChecksum = true) { char[] monthChars = { 'A', 'B', 'C', 'D', 'E', 'H', 'L', 'M', 'P', 'R', 'S', 'T' }; if (string.IsNullOrWhiteSpace(lastName)) { lastName = Name.Last(); } if (string.IsNullOrWhiteSpace(firstName)) { firstName = Name.First(); } var male = RandomNumber.Next(2) == 0; // even probability to be male or female var sb = new StringBuilder(); sb.Append(GetFiscalCodeSqueezedName(lastName, false)); sb.Append(GetFiscalCodeSqueezedName(firstName, true)); sb.Append((birthday.Year % 100).ToString("00", CultureInfo.InvariantCulture)); sb.Append(monthChars[birthday.Month - 1]); sb.Append((birthday.Day + (male ? 0 : 40)).ToString("00", CultureInfo.InvariantCulture)); sb.Append(ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.FiscalCode_TownCodes.Codes)).Random()); var checksum = ComputeChecksumFiscalCode(sb.ToString(), validChecksum); sb.Append(checksum); return(sb.ToString()); }
/// <summary> /// Gets a random ip v4 address. /// </summary> /// <returns>A random ip v4 address.</returns> // ReSharper disable once InconsistentNaming public static string IPv4Address() { const int min = 2; const int max = 255; return(string.Join(".", 4.Times(c => RandomNumber.Next(min, max).ToString(CultureInfo.CurrentCulture)))); }
/// <summary> /// Gets a random ip v6 address. /// </summary> /// <returns>A random ip v6 address.</returns> public static string IPv6Address() { const int MIN = 0; const int MAX = 65536; return(string.Join(":", 8.Times(c => RandomNumber.Next(MIN, MAX).ToString("x", CultureInfo.CurrentCulture)))); }
/// <summary> /// Gets a random ip v4 address. /// </summary> /// <returns>A random ip v4 address.</returns> public static string IPv4Address() { const int MIN = 2; const int MAX = 255; return(string.Join(".", 4.Times(c => RandomNumber.Next(MIN, MAX).ToString(CultureInfo.CurrentCulture)))); }
/// <summary> /// Creates a name using random format. /// </summary> /// <returns>The randomly created name.</returns> public static string FullName() { lock (s_formatsLock) { return(FullName(s_formats.ElementAt(RandomNumber.Next(s_formats.Count() - 1)))); } }
public static string Ticker() { var length = RandomNumber.Next(2, 4); return(new string(Enumerable.Repeat(TickerCharacters, length) .Select(s => s[RandomNumber.Next(s.Length - 1)]).ToArray())); }
public static string UkNationalInsuranceNumber(bool formatted = false) { var notAllowedPrefixes = Resources.Identification.UkNationalInsuranceNotAllowedPrefix .Split(Config.Separator) .ToArray(); string prefix; while (true) { prefix = $"{Resources.Identification.UkNationalInsuranceFirstDigit.Split(Config.Separator).Random()}{Resources.Identification.UkNationalInsuranceSecondDigit.Split(Config.Separator).Random()}"; if (!notAllowedPrefixes.Contains(prefix)) { break; } } var number = string.Empty; for (var i = 0; i < 6; i++) { number += RandomNumber.Next(0, 9); } var suffix = $"{Resources.Identification.UkNationalInsuranceSuffix.Split(Config.Separator).Random()}"; return(formatted ? $"{prefix} {number.Substring(0,2)} {number.Substring(2, 2)} {number.Substring(4, 2)} {suffix}" : $"{prefix}{number}{suffix}"); }
public static DateTime DateOfBirth() { var rnd = new Random((int)DateTime.UtcNow.Ticks); var first = rnd.NextDouble(); var second = rnd.NextDouble(); var randStdNormal = Math.Sqrt(-2.0 * Math.Log(first)) * Math.Sin(2.0 * Math.PI * second); const double average = MaxAgeAllowed * .5; var randNormal = average + 46 * randStdNormal; var yearsToSubtract = (int)Math.Abs(randNormal); if (yearsToSubtract > MaxAgeAllowed) { yearsToSubtract = (int)average; } var now = DateTime.UtcNow; var randomDay = RandomNumber.Next(1, 365); // Skip leap years for simplicity if (yearsToSubtract < 1) { randomDay = RandomNumber.Next(1, now.DayOfYear); } var gaussianDate = now.AddYears(yearsToSubtract * -1).AddDays(randomDay * -1); return(gaussianDate.Date); }
/// <summary> /// Gets a random ip v6 address. /// </summary> /// <returns>A random ip v6 address.</returns> // ReSharper disable once InconsistentNaming public static string IPv6Address() { const int min = 0; const int max = 65536; return(string.Join(":", 8.Times(c => RandomNumber.Next(min, max).ToString("x", CultureInfo.CurrentCulture)))); }
public static decimal Coupon() { var minor = RandomNumber.Next(0, 1000); var major = RandomNumber.Next(0, 12) * 1000; return(decimal.Round(Convert.ToDecimal(major + minor) / 1000, 3)); }
public static DateTime Maturity(int minimumMaturityInMonths = 6, int maximumMaturityInMonths = 180) { var months = RandomNumber.Next(minimumMaturityInMonths, maximumMaturityInMonths); var days = RandomNumber.Next(1, 28); var date = DateTime.Now.Date.AddMonths(months).AddDays(days); return(date); }
/// <summary> /// Choose a random enum. /// </summary> public static T Random <T>() where T : struct, IConvertible { var values = Enum.GetValues(typeof(T)); return((T)values .GetValue(RandomNumber.Next(values.Length))); }
/// <summary> /// Gets a random sentence. /// </summary> /// <param name="minWordCount">The minimum word count.</param> /// <returns>The random sentence</returns> /// <exception cref="ArgumentOutOfRangeException"> /// Minimum word count must be greater than zero /// </exception> /// <seealso cref="Sentence()" /> /// <seealso cref="Words(int)" /> public static string Sentence(int minWordCount) { if (minWordCount <= 0) { throw new ArgumentOutOfRangeException("minWordCount", "Minimum word count must be greater than zero"); } return(string.Join(" ", Words(minWordCount + RandomNumber.Next(6))).Capitalise() + "."); }
public static string Paragraph(int minSentenceCount) { if (minSentenceCount <= 0) { throw new ArgumentException(@"Count must be greater than zero", nameof(minSentenceCount)); } return(string.Join(" ", Sentences(minSentenceCount + RandomNumber.Next(3)).ToArray())); }
public static string Sentence(int minWordCount) { if (minWordCount <= 0) { throw new ArgumentException(@"Count must be greater than zero", nameof(minWordCount)); } return(string.Join(" ", Words(minWordCount + RandomNumber.Next(6)).ToArray()).Capitalise() + "."); }
/// <summary> /// Gets a random logo URL. /// </summary> /// <param name="useSsl">Set to <c>true</c> if https should be used, otherwise <c>false</c></param> /// <returns>A random logo URL</returns> public static string Logo(bool useSsl) { int randNum = RandomNumber.Next(13) + 1; return("{0}://pigment.github.io/fake-logos/logos/medium/color/{1}.png".FormatCulture( useSsl ? "https" : "http", randNum )); }
/// <summary> /// Gets a random paragraph. /// </summary> /// <param name="minSentenceCount">The minimum sentence count.</param> /// <returns>The random paragraph.</returns> /// <exception cref="ArgumentOutOfRangeException">Minimum sentence count must be greater than zero.</exception> /// <seealso cref="Paragraph()" /> /// <seealso cref="Sentences(int)" /> public static string Paragraph(int minSentenceCount) { if (minSentenceCount <= 0) { throw new ArgumentOutOfRangeException("minSentenceCount", "Minimum sentence count must be greater than zero."); } return(string.Join(" ", Sentences(minSentenceCount + RandomNumber.Next(3)))); }
/// <summary> /// Generates random characters with the specified <paramref name="charCount">character count</paramref>. /// </summary> /// <param name="charCount">The character count.</param> /// <returns>The random characters.</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// Character count must be more than zero. /// </exception> public static string Characters(int charCount = 255) { if (charCount <= 0) { throw new ArgumentOutOfRangeException("charCount", "Character count must be more than zero."); } byte[] characters = charCount.Times(count => (byte)RandomNumber.Next(33, 126)).ToArray(); return(Encoding.UTF8.GetString(characters, 0, charCount)); }
public static string ContentTitle(int numberOfWords) { if (numberOfWords <= 0) { numberOfWords = RandomNumber.Next(3, 8); } string contentTitle = string.Join(" ", Words(numberOfWords)).Capitalise(); return(contentTitle); }
/// <summary> /// Generates a 10 digit NPI (National Provider Identifier issued to health care providers /// in the United States) /// </summary> /// <returns>The generated NPI</returns> /// <remarks> /// Description of the NPI standard is at /// https://en.wikipedia.org/wiki/National_Provider_Identifier. The NPI has replaced the /// unique physician identification number (UPIN). /// </remarks> public static string NPI() { var sb = new StringBuilder(); for (int i = 0; i < 10; i++) { sb.Append(RandomNumber.Next(10)); } return(sb.ToString()); }
/// <summary> /// Generates a EAN Code /// </summary> /// <param name="validChecksum"> /// Indicates whether the generated EAN has a valid checksum or not /// </param> /// <returns>The generated EAN</returns> /// <remarks> /// Description of the EAN standard is at /// <a href="https://en.wikipedia.org/wiki/International_Article_Number">wikipedia.</a> /// Checksum routines are at <a href="http://www.isbn-check.de/servejs.pl?src=isbnfront.perlserved.js">isbn-check</a> /// </remarks> public static string EAN(bool validChecksum = true) { int[] v = new int[12]; for (int i = 0; i < 12; i++) { v[i] = RandomNumber.Next(0, 10); } var prefix = string.Join(string.Empty, v); return(prefix + ComputeChecksum(validChecksum, v)); }
/// <summary> /// Gets a random password. /// </summary> /// <param name="minLength">The minimum length.</param> /// <param name="maxLength">The maximum length.</param> /// <returns>The random password.</returns> public static string Password(int minLength, int maxLength) { string result = Lorem.Characters(minLength); int difference = RandomNumber.Next(maxLength - minLength + 1); if (difference > 0) { result += Lorem.Characters(difference); } return(result); }
public static string ContentTags(int numberOfTags) { if (numberOfTags <= 0) { numberOfTags = RandomNumber.Next(2, 5); } string tags = string.Join(",", Words(numberOfTags).Cast <string>() .Where(c => !string.IsNullOrWhiteSpace(c)) .Distinct()); return(tags); }
public static string UKNationalInsuranceNumber() { var NINumber = new StringBuilder(); NINumber.Append(_alphabet.Random()); NINumber.Append(_alphabet.Random()); for (var i = 0; i < 6; i++) { NINumber.Append(RandomNumber.Next(0, 9)); } NINumber.Append(_alphabet.Random()); return(NINumber.ToString()); }
/// <summary> /// Generates a Singaporean National Registration Identity Card (NRIC) for holder who is /// born between specified ages. /// </summary> /// <param name="validChecksum"> /// Indicates whether the generated NRIC has a valid checksum or not /// </param> /// <param name="minAge">Minimum age of the holder</param> /// <param name="maxAge">Maximum age of the holder</param> /// <returns>The generated NRIC</returns> /// <remarks> /// Description of the NRIC standard is at /// <see href="https://en.wikipedia.org/wiki/National_Registration_Identity_Card" />. This /// ID was issued for the first time in 1965 in Singapore. See also: <see href="https://github.com/stympy/faker/blob/master/lib/faker/code.rb#L32" /> /// </remarks> public static string NRIC(bool validChecksum = true, int minAge = 18, int maxAge = 65) { var birthYear = Date.Birthday(minAge, maxAge).Year; var prefix = birthYear < 2000 ? 'S' : 'T'; var v = new int[7]; for (int i = 0; i < 7; i++) { v[i] = RandomNumber.Next(10); } var checksum = ComputeChecksumNric(v, prefix, validChecksum); return(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", prefix, string.Join(string.Empty, v), checksum)); }
public static string UkNationalInsuranceNumber() { var niNumber = new StringBuilder(); niNumber.Append(Resources.Identification.Alphabet.Split(Config.Separator).Random()); niNumber.Append(Resources.Identification.Alphabet.Split(Config.Separator).Random()); for (var i = 0; i < 6; i++) { niNumber.Append(RandomNumber.Next(0, 9)); } niNumber.Append(Resources.Identification.Alphabet.Split(Config.Separator).Random()); return(niNumber.ToString()); }
/// <summary> /// Generates an ISBN-13 Code /// </summary> /// <param name="validChecksum"> /// Indicates whether the generated ISBN has a valid checksum or not /// </param> /// <returns>The generated ISBN-13</returns> /// <remarks> /// Description of the ISBN standard is at /// <a href="https://en.wikipedia.org/wiki/International_Standard_Book_Number">wikipedia</a>. /// Checksum routines are at <a href="http://www.isbn-check.de/servejs.pl?src=isbnfront.perlserved.js">isbn-check</a> /// </remarks> /// <seealso cref="ISBN10" /> public static string ISBN13(bool validChecksum = true) { int[] v = new int[12]; // ISBN13 starts with "978" or "979" v[0] = 9; v[1] = 7; v[2] = RandomNumber.Next(8, 10); for (int i = 3; i < 12; i++) { v[i] = RandomNumber.Next(10); } var prefix = string.Join(string.Empty, v); return(prefix + ComputeChecksum(validChecksum, v)); }
/// <summary> /// Generates an ISBN-10 Code /// </summary> /// <param name="validChecksum"> /// Indicates whether the generated ISBN has a valid checksum or not /// </param> /// <returns>The generated ISBN-10</returns> /// <remarks> /// Description of the ISBN standard is at /// <see href="https://en.wikipedia.org/wiki/International_Standard_Book_Number" /> /// Checksum routines are at <see href="http://www.isbn-check.de/servejs.pl?src=isbnfront.perlserved.js" /> /// </remarks> public static string ISBN10(bool validChecksum = true) { int[] v = new int[9]; for (int i = 0; i < 9; i++) { v[i] = RandomNumber.Next(0, 10); } var checksum = ComputeChecksumIsbn10(v); if (!validChecksum) { checksum = (checksum + 1) % 11; // set wrong checksum } var prefix = string.Join(string.Empty, v); return(prefix + (checksum < 10 ? checksum.ToString(CultureInfo.InvariantCulture) : "X")); }
/// <summary> /// Generates a EAN Code /// </summary> /// <param name="validChecksum"> /// Indicates whether the generated EAN has a valid checksum or not /// </param> /// <returns>The generated EAN</returns> /// <remarks> /// Description of the EAN standard is at /// <see href="https://en.wikipedia.org/wiki/International_Article_Number" /> Checksum /// routines are at <see href="http://www.isbn-check.de/servejs.pl?src=isbnfront.perlserved.js" /> /// </remarks> public static string EAN(bool validChecksum = true) { int[] v = new int[12]; for (int i = 0; i < 12; i++) { v[i] = RandomNumber.Next(0, 10); } var checksum = ComputeChecksumEan(v); if (!validChecksum) { checksum = (checksum + 1) % 10; // set wrong checksum } var prefix = string.Join(string.Empty, v); return(prefix + checksum); }
public static T Random <T>() { var type = typeof(T); if (!type.IsEnum) { throw new ArgumentException("The given type is not an enum"); } var values = System.Enum.GetValues(type); if (values.Length == 0) { throw new ArgumentException("The given enum doesn't have any values"); } var index = RandomNumber.Next(0, values.Length - 1); return((T)values.GetValue(index)); }