Ejemplo 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());
        }
        public virtual T Distort(T item)
        {
            if (enums.Count > 0)
            {
                if (RandomBoolean.Chance(1, 5))
                {
                    PropertyInfo prop   = enums[RandomInteger.NextInteger(enums.Count)];
                    Array        values = prop.PropertyType.GetEnumValues();
                    prop.SetValue(item, values.GetValue(RandomInteger.NextInteger(values.Length)));
                }
            }

            return(item);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Distorts a string by randomly replacing characters in it.
        /// </summary>
        /// <param name="value">a string to distort.</param>
        /// <returns>a distored string.</returns>
        public static string Distort(string value)
        {
            value = value.ToLower();

            if (RandomBoolean.Chance(1, 5))
            {
                value = value.Substring(0, 1).ToUpper() + value.Substring(1);
            }

            if (RandomBoolean.Chance(1, 3))
            {
                value = value + Pick(_symbols);
            }

            return(value);
        }
        public List <T> DistortList(List <T> items, int minSize, int maxSize = 0, float probability = 1, DataReferences references = null)
        {
            maxSize = Math.Max(minSize, maxSize);
            int size = RandomInteger.NextInteger(minSize, maxSize);

            for (int index = 0; items.Count > 0 && index < size; index++)
            {
                if (RandomBoolean.Chance(probability * 100, 100))
                {
                    var itemIndex = RandomInteger.NextInteger(items.Count);
                    items[itemIndex] = Distort(items[itemIndex]);
                }
            }

            return(items);
        }
Ejemplo n.º 5
0
        public void TestChance()
        {
            bool value;

            value = RandomBoolean.Chance(5, 10);
            Assert.True(value || !value);

            value = RandomBoolean.Chance(5, 5);
            Assert.True(value || !value);

            value = RandomBoolean.Chance(0, 0);
            Assert.True(!value);

            value = RandomBoolean.Chance(-1, 0);
            Assert.True(!value);

            value = RandomBoolean.Chance(-1, -1);
            Assert.True(!value);
        }
Ejemplo n.º 6
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());
        }