public static string GenerateDomainName(int numberOfLabels)
        {
            if (numberOfLabels < 1)
            {
                throw new ArgumentException();
            }

            var minLength  = numberOfLabels * 3;
            var wordLength = random.Next(minLength, RandomDomainNameGenerator.MaxDomainNameLength + 1);

            string randomWord = RandomWordGenerator.GenerateWord(wordLength);

            IList <int> dotPositions = RandomDomainNameGenerator.GenerateDotPositions(wordLength, numberOfLabels);

            return(RandomDomainNameGenerator.ReplaceStringPositionsByDots(randomWord, dotPositions));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Regex regex = new Regex(@"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)+$");

            for (int tries = 0; tries < 100; ++tries)
            {
                int labels = random.Next(1, 40);
                Console.WriteLine("Labels: {0}", labels);

                string domainName = RandomDomainNameGenerator.GenerateDomainName(labels);
                Console.WriteLine("Domain: {0}", domainName);

                Debug.Assert(regex.IsMatch(domainName), string.Format("The domain name '{0}' is not valid", domainName));
            }

            Console.ReadLine();
        }