Esempio n. 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());
        }
Esempio n. 2
0
        /// <summary>
        /// Picks a random element from specified array.
        /// </summary>
        /// <typeparam name="T">the class type</typeparam>
        /// <param name="values">an array of any type</param>
        /// <returns>a randomly picked item.</returns>
        public static T Pick <T>(T[] values)
        {
            if (values == null || values.Length == 0)
            {
                return(default(T));
            }

            return(values[RandomInteger.NextInteger(values.Length)]);
        }
        /// <summary>
        /// Picks a random character from an array of string..
        /// </summary>
        /// <param name="values">a string to pick from</param>
        /// <returns>a randomly picked string.</returns>
        public static string Pick(String[] values)
        {
            if (values == null || values.Length == 0)
            {
                return("");
            }

            int index = RandomInteger.NextInteger(values.Length);

            return(values[index]);
        }
        /// <summary>
        /// Picks a random character from a string.
        /// </summary>
        /// <param name="values">a string to pick a char from</param>
        /// <returns>a randomly picked char.</returns>
        public static char Pick(string values)
        {
            if (values == null || values.Length == 0)
            {
                return('\0');
            }

            int index = RandomInteger.NextInteger(values.Length);

            return(values[index]);
        }
Esempio n. 5
0
        /// <summary>
        /// Picks a random element from specified array.
        /// </summary>
        /// <typeparam name="T">the class type</typeparam>
        /// <param name="values">an list of values of any type</param>
        /// <returns>a randomly picked item.</returns>
        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]);
        }
Esempio n. 6
0
        /// <summary>
        /// Generates a random phone number. The phone number has the format: (XXX) XXX-YYYY
        /// </summary>
        /// <returns>a random phone number.</returns>
        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());
        }
Esempio n. 7
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());
        }
        /// <summary>
        /// Generates a random string, consisting of upper and lower case letters (of the English alphabet),
        /// digits(0-9), and symbols("_,.:-/.[].{},#-!,$=%.+^.&*-() ").
        /// </summary>
        /// <param name="minLength">(optional) minimum string length.</param>
        /// <param name="maxLength">maximum string length.</param>
        /// <returns>a random string.</returns>
        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());
        }
Esempio n. 9
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());
        }
        /// <summary>
        /// Generates random alpha characted [A-Za-z]
        /// </summary>
        /// <returns>a random characted.</returns>
        public static char NextAlphaChar()
        {
            int index = RandomInteger.NextInteger(_alpha.Length);

            return(_alpha[index]);
        }