RandomNumber() public static method

Gets a random number from 0 to any
public static RandomNumber ( ) : int
return int
Ejemplo n.º 1
0
        /// <summary>
        /// Generate password method
        /// </summary>
        /// <param name="length">Length to use</param>
        /// <param name="nonAlphaNumericChars">Number of special characters</param>
        /// <returns>Password as string</returns>
        private static string GeneratePassword(int length, int nonAlphaNumericChars)
        {
            string allowedChars       = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
            string allowedNonAlphaNum = "!@#$%^&*()_-+=[{]};:<>|./?";

            if (nonAlphaNumericChars > length || length <= 0 || nonAlphaNumericChars < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            char[] pass = new char[length];
            int[]  pos = new int[length];
            int    i = 0, j = 0, temp = 0;
            bool   flag = false;

            // Random the position values of the pos array for the string Pass
            while (i < length - 1)
            {
                j    = 0;
                flag = false;
                temp = Number.RandomNumber(0, length);
                for (j = 0; j < length; j++)
                {
                    if (temp == pos[j])
                    {
                        flag = true;
                        j    = length;
                    }
                }

                if (!flag)
                {
                    pos[i] = temp;
                    i++;
                }
            }

            // Random the AlphaNumericChars
            for (i = 0; i < length - nonAlphaNumericChars; i++)
            {
                pass[i] = allowedChars[Number.RandomNumber(0, allowedChars.Length)];
            }

            // Random the NonAlphaNumericChars
            for (i = length - nonAlphaNumericChars; i < length; i++)
            {
                pass[i] = allowedNonAlphaNum[Number.RandomNumber(0, allowedNonAlphaNum.Length)];
            }

            // Set the sorted array values by the pos array for the rigth posistion
            char[] sorted = new char[length];
            for (i = 0; i < length; i++)
            {
                sorted[i] = pass[pos[i]];
            }

            string password = new string(sorted);

            return(password);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a random Canadian zip
        /// </summary>
        /// <returns>A string value</returns>
        public static string CanadianZipCode()
        {
            List <string> alpha = new List <string>
            {
                "A", "B", "C", "E", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "V", "W", "X", "Y", "Z"
            };
            List <int> numeric = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            };
            List <string> alphaFirst = new List <string>
            {
                "A", "B", "C", "E", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "V", "X", "Y"
            };
            StringBuilder newZip = new StringBuilder();

            for (int i = 0; i <= 5; i++)
            {
                if (i == 0)
                {
                    newZip.Append(alphaFirst[Number.RandomNumber(0, alphaFirst.Count - 1)]);
                }
                else if ((i % 2) == 0)
                {
                    newZip.Append(alpha[Number.RandomNumber(0, alpha.Count - 1)]);
                }
                else
                {
                    newZip.Append(numeric[Number.RandomNumber(0, numeric.Count - 1)]);
                }
            }

            return(newZip.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a random alpha character
        /// </summary>
        /// <returns>Character to use</returns>
        public static char Character()
        {
            int  num = Number.RandomNumber(0, 26); // Zero to 25
            char val = (char)('a' + num);

            return(val);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Получить случайны город России
 /// </summary>
 /// <returns>A string value</returns>
 public static string RusCity()
 {
     if (rusCity == null)
     {
         rusCity = XML.GetListString("RUSCity");
     }
     return(rusCity[Number.RandomNumber(0, rusCity.Count - 1)]);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets a random country
        /// </summary>
        /// <returns>A string value</returns>
        public static string Country()
        {
            if (country == null)
            {
                country = XML.GetListString("Country");
            }

            return(country[Number.RandomNumber(0, country.Count - 1)]);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets a random password
        /// </summary>
        /// <param name="length">Length of password</param>
        /// <param name="useSpecialChars">Use special characters.  If true, random number of characters</param>
        /// <returns>Password as string</returns>
        public static string Password(int length, bool useSpecialChars)
        {
            if (useSpecialChars)
            {
                return(Password(length, Number.RandomNumber(1, 5)));
            }

            return(Password(length, 0));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets a random street name
        /// </summary>
        /// <returns>A string value</returns>
        public static string StreetName()
        {
            if (streetName == null)
            {
                streetName = XML.GetListString("StreetName");
            }

            return(streetName[Number.RandomNumber(0, streetName.Count - 1)]);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets a random province abbreviation
        /// </summary>
        /// <returns>A string value</returns>
        public static string ProvinceAbbreviation()
        {
            if (provinceAbbreviations == null)
            {
                provinceAbbreviations = XML.GetListString("ProvinceAbbreviations");
            }

            return(provinceAbbreviations[Number.RandomNumber(0, provinceAbbreviations.Count - 1)]);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets a random industry
        /// </summary>
        /// <returns>A string value</returns>
        public static string Industry()
        {
            if (industry == null)
            {
                industry = XML.GetListString("Company", "Industry");
            }

            return(industry[Number.RandomNumber(0, industry.Count - 1)]);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a random state abbreviation
        /// </summary>
        /// <returns>String of state abbreviation</returns>
        public static string StateAbbreviation()
        {
            if (stateAbbreviations == null)
            {
                stateAbbreviations = XML.GetListString("Address", "StateAbbreviations");
            }

            return(stateAbbreviations[Number.RandomNumber(0, stateAbbreviations.Count - 1)]);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets a random United States county
        /// </summary>
        /// <returns>A string value</returns>
        public static string USCounty()
        {
            if (usCounty == null)
            {
                usCounty = XML.GetListString("USCounty");
            }

            return(usCounty[Number.RandomNumber(0, usCounty.Count - 1)]);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets a random united states zip code
        /// </summary>
        /// <returns>A string value</returns>
        public static string USZipCode()
        {
            if (usZipCode == null)
            {
                usZipCode = XML.GetListString("USZipCode");
            }

            return(usZipCode[Number.RandomNumber(0, usZipCode.Count - 1)]);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets a random street suffix
        /// </summary>
        /// <returns>A string value</returns>
        public static string StreetSuffix()
        {
            if (streetSuffix == null)
            {
                streetSuffix = XML.GetListString("StreetSuffix");
            }

            return(streetSuffix[Number.RandomNumber(0, streetSuffix.Count - 1)]);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets a random secondary address
        /// </summary>
        /// <returns>A string value</returns>
        public static string SecondaryAddress()
        {
            if (secondaryAddress == null)
            {
                secondaryAddress = XML.GetListString("SecondaryAddress");
            }

            return(secondaryAddress[Number.RandomNumber(0, secondaryAddress.Count - 1)] + Number.RandomNumber(0, 1000));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets a random city suffix
        /// </summary>
        /// <returns>A string value</returns>
        public static string CitySuffix()
        {
            if (citySuffix == null)
            {
                citySuffix = XML.GetListString("CitySuffix");
            }

            return(citySuffix[Number.RandomNumber(0, citySuffix.Count - 1)]);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets a suffix value
        /// </summary>
        /// <returns>String of suffix</returns>
        public static string Suffix()
        {
            if (suffix == null)
            {
                suffix = XML.GetListString("Company", "Suffix");
            }

            return(suffix[Number.RandomNumber(0, suffix.Count - 1)]);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets a random sector
        /// </summary>
        /// <returns>A string value</returns>
        public static string Sector()
        {
            if (sector == null)
            {
                sector = XML.GetListString("Company", "Sector");
            }

            return(sector[Number.RandomNumber(0, sector.Count - 1)]);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets a random province
        /// </summary>
        /// <returns>A string value</returns>
        public static string Province()
        {
            if (provinces == null)
            {
                provinces = XML.GetListString("Provinces");
            }

            return(provinces[Number.RandomNumber(0, provinces.Count - 1)]);
        }
Ejemplo n.º 19
0
        private static string Name()
        {
            if (name == null)
            {
                name = XML.GetListString("Company", "Name");
            }

            return(name[Number.RandomNumber(0, name.Count - 1)]);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets a random system color
        /// </summary>
        /// <returns>A string value</returns>
        public static string SystemColor()
        {
            if (systemColors == null)
            {
                systemColors = LoadSystemColors();
            }

            return(systemColors[Number.RandomNumber(0, systemColors.Count - 1)].Name);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets a random male first name
        /// </summary>
        /// <returns>A string value</returns>
        public static string MaleFirstName()
        {
            if (maleFirstName == null)
            {
                maleFirstName = XML.GetListString("MaleFirstName");
            }

            return(maleFirstName[Number.RandomNumber(0, maleFirstName.Count - 1)]);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets a random color
        /// </summary>
        /// <returns>A string value</returns>
        public static string ColorString()
        {
            if (colors == null)
            {
                colors = XML.GetListString("Color");
            }

            return(colors[Number.RandomNumber(0, colors.Count - 1)]);
        }
        /// <summary>
        /// Gets a random credit card type
        /// </summary>
        /// <returns>string of random credit card</returns>
        public static string CreditCardType()
        {
            if (creditCardType == null)
            {
                creditCardType = XML.GetListString("CreditCardType");
            }

            return(creditCardType[Number.RandomNumber(0, creditCardType.Count - 1)]);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Gets a random letter
        /// </summary>
        /// <returns>A <see cref="char"/></returns>
        public static char Letter()
        {
            string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            if (Number.Bool())
            {
                return(chars[Number.RandomNumber(0, chars.Length - 1)]);
            }

            return(char.ToLower(chars[Number.RandomNumber(0, chars.Length - 1)]));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets a random symbol
        /// </summary>
        /// <returns>A string value</returns>
        public static string Symbol()
        {
            string val = string.Empty;

            for (int i = 0; i < Number.RandomNumber(3, 5); i++)
            {
                val += Utilities.Character();
            }

            return(val.ToUpper());
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets a random last name
        /// </summary>
        /// <returns>A string value</returns>
        public static string LastName()
        {
            lock (lastNameLock)
            {
                if (lastName == null)
                {
                    lastName = XML.GetListString("LastName");
                }

                return(lastName[Number.RandomNumber(0, lastName.Count - 1)]);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Gets a random female first name
        /// </summary>
        /// <returns>A string value</returns>
        public static string FemaleFirstName()
        {
            lock (femaleFirstNameLock)
            {
                if (femaleFirstName == null)
                {
                    femaleFirstName = XML.GetListString("FemaleFirstName");
                }

                return(femaleFirstName[Number.RandomNumber(0, femaleFirstName.Count - 1)]);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Gets a random ethnicity
        /// </summary>
        /// <returns>A string value</returns>
        public static string Ethnicity()
        {
            lock (ethnicityLock)
            {
                if (ethnicity == null)
                {
                    ethnicity = XML.GetListString("Person", "Ethnicity");
                }

                return(ethnicity[Number.RandomNumber(0, ethnicity.Count - 1)]);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets a random product
        /// </summary>
        /// <returns>A <see cref="string"/></returns>
        public static string Product()
        {
            lock (productsLock)
            {
                if (products == null)
                {
                    products = XML.GetListString("Commerce", "Product");
                }

                return(products[Number.RandomNumber(0, products.Count - 1)]);
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets a random department
        /// </summary>
        /// <returns>A <see cref="string"/></returns>
        public static string Department()
        {
            lock (departmentLock)
            {
                if (departments == null)
                {
                    departments = XML.GetListString("Commerce", "Department");
                }

                return(departments[Number.RandomNumber(0, departments.Count - 1)]);
            }
        }