示例#1
0
        /// <summary>
        /// Generates a random text, consisting of first names, last names, colors, stuffs, adjectives, verbs, and punctuation marks.
        /// </summary>
        /// <param name="minSize">minimum amount of words to generate. Text will contain 'minSize' words if 'maxSize' is omitted.</param>
        /// <param name="maxSize">(optional) maximum amount of words to generate.</param>
        /// <returns>a random text.</returns>
        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());
        }
示例#2
0
        /// <summary>
        /// Generates a random text that consists of random number of random words separated by spaces.
        /// </summary>
        /// <param name="min">(optional) a minimum number of words.</param>
        /// <param name="max">a maximum number of words.</param>
        /// <returns>a random text.</returns>
        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());
        }
示例#3
0
        public void TestPick()
        {
            Assert.True(RandomString.Pick("") == '\0');
            char charVariable = RandomString.Pick(chars);

            Assert.True(chars.IndexOf(charVariable) != -1);

            string[] valuesEmpty = { };
            Assert.True(RandomString.Pick(valuesEmpty) == "");

            string[] values = { "ab", "cd" };
            string   result = RandomString.Pick(values);

            Assert.True(result == "ab" || result == "cd");
        }
示例#4
0
        /// <summary>
        /// Generates a random person's name which has the following structure
        /// optional prefix - first name - second name - optional suffix
        /// </summary>
        /// <returns>a random name.</returns>
        public static string Name()
        {
            StringBuilder result = new StringBuilder();

            if (RandomBoolean.Chance(3, 5))
            {
                result.Append(RandomString.Pick(_namePrefixes)).Append(" ");
            }

            result.Append(RandomString.Pick(_firstNames))
            .Append(" ")
            .Append(RandomString.Pick(_lastNames));

            if (RandomBoolean.Chance(5, 10))
            {
                result.Append(" ").Append(RandomString.Pick(_nameSuffixes));
            }

            return(result.ToString());
        }
示例#5
0
        /// <summary>
        /// Generates a random phrase which consists of few words separated by spaces.
        /// The first word is capitalized, others are not.
        /// </summary>
        /// <param name="minSize">(optional) minimum string length.</param>
        /// <param name="maxSize">maximum string length.</param>
        /// <returns>a random phrase.</returns>
        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());
        }
示例#6
0
 /// <summary>
 /// Generates a random noun. The result value is capitalized.
 /// </summary>
 /// <returns>a random noun.</returns>
 public static string Stuff()
 {
     return(RandomString.Pick(_stuffs));
 }
示例#7
0
 /// <summary>
 /// Generates a random color name. The result value is capitalized.
 /// </summary>
 /// <returns>a random color name.</returns>
 public static string Color()
 {
     return(RandomString.Pick(_colors));
 }
示例#8
0
 /// <summary>
 /// Generates a random word from available first names, last names, colors, stuffs, adjectives, or verbs.
 /// </summary>
 /// <returns>a random word.</returns>
 public static string Word()
 {
     return(RandomString.Pick(_allWords));
 }
示例#9
0
 /// <summary>
 /// Generates a random verb. The result value is capitalized.
 /// </summary>
 /// <returns>a random verb.</returns>
 public static string Verb()
 {
     return(RandomString.Pick(_verbs));
 }
示例#10
0
 /// <summary>
 /// Generates a random adjective. The result value is capitalized.
 /// </summary>
 /// <returns>a random adjective.</returns>
 public static string Adjective()
 {
     return(RandomString.Pick(_adjectives));
 }