public static string Text(int minSize, int maxSize) { maxSize = Math.Max(minSize, maxSize); int size = RandomInteger.NextInteger(minSize, maxSize); StringBuilder result = new StringBuilder(); result.Append(RandomString.Pick(_allWords)); while (result.Length < size) { String next = RandomString.Pick(_allWords); if (RandomBoolean.Chance(4, 6)) { next = " " + next.ToLower(); } else if (RandomBoolean.Chance(2, 5)) { next = RandomString.Pick(":,-") + next.ToLower(); } else if (RandomBoolean.Chance(3, 5)) { next = RandomString.Pick(":,-") + " " + next.ToLower(); } else { next = RandomString.Pick(".!?") + " " + next; } result.Append(next); } return(result.ToString()); }
public void TestNextInteger() { float value = RandomInteger.NextInteger(5); Assert.True(value <= 5); value = RandomInteger.NextInteger(2, 5); Assert.True(value <= 5 && value >= 2); }
public static TimeSpan NextTime() { int hour = RandomInteger.NextInteger(0, 24); int min = RandomInteger.NextInteger(0, 60); int sec = RandomInteger.NextInteger(0, 60); int millis = RandomInteger.NextInteger(0, 1000); return(new TimeSpan(hour, min, sec, millis)); }
public static T Pick <T>(T[] values) { if (values == null || values.Length == 0) { return(default(T)); } return(values[RandomInteger.NextInteger(values.Length)]); }
public static string Pick(String[] values) { if (values == null || values.Length == 0) { return(""); } int index = RandomInteger.NextInteger(values.Length); return(values[index]); }
public static char Pick(string values) { if (values == null || values.Length == 0) { return('\0'); } int index = RandomInteger.NextInteger(values.Length); return(values[index]); }
public static T Pick <T>(List <T> values) { if (values == null || values.Count == 0) { return(default(T)); } int index = RandomInteger.NextInteger(values.Count); return(values[index]); }
public static string Phone() { StringBuilder result = new StringBuilder(); result.Append("(") .Append(RandomInteger.NextInteger(111, 999)) .Append(") ") .Append(RandomInteger.NextInteger(111, 999)) .Append("-") .Append(RandomInteger.NextInteger(0, 9999)); return(result.ToString()); }
public static string Words(int min, int max) { StringBuilder result = new StringBuilder(); int count = RandomInteger.NextInteger(min, max); for (int i = 0; i < count; i++) { result.Append(RandomString.Pick(_allWords)); } return(result.ToString()); }
public static string NextString(int minLength, int maxLength) { StringBuilder result = new StringBuilder(); int length = RandomInteger.NextInteger(minLength, maxLength); for (int i = 0; i < length; i++) { int index = RandomInteger.NextInteger(_chars.Length); result.Append(_chars[index]); } return(result.ToString()); }
public static string Phrase(int minSize, int maxSize) { maxSize = Math.Max(minSize, maxSize); int size = RandomInteger.NextInteger(minSize, maxSize); if (size <= 0) { return(""); } StringBuilder result = new StringBuilder(); result.Append(RandomString.Pick(_allWords)); while (result.Length < size) { result.Append(" ").Append(RandomString.Pick(_allWords).ToLower()); } return(result.ToString()); }
public static DateTime NextDate(int minYear, int maxYear) { int currentYear = DateTime.Now.Year; minYear = minYear == 0 ? currentYear - RandomInteger.NextInteger(10) : minYear; maxYear = maxYear == 0 ? currentYear : maxYear; int year = RandomInteger.NextInteger(minYear, maxYear); int month = RandomInteger.NextInteger(1, 13); int day = RandomInteger.NextInteger(1, 32); if (month == 2) { day = Math.Min(28, day); } else if (month == 4 || month == 6 || month == 9 || month == 11) { day = Math.Min(30, day); } return(new DateTime(year, month, day, 0, 0, 0, 0, DateTimeKind.Utc)); }
public static char NextAlphaChar() { int index = RandomInteger.NextInteger(_alpha.Length); return(_alpha[index]); }
public static DateTime NextDateTime(int minYear, int maxYear) { return(NextDate(minYear, maxYear) .AddSeconds(RandomInteger.NextInteger(3600 * 24 * 365))); }