Random Url - CSharp System

CSharp examples for System:Random

Description

Random Url

Demo Code

//  Copyright (c) 2014 IBT  All rights reserved.
using System.Text;
using System;/*from  w  w w. j  av  a2 s  .  c  om*/

public class Main{
        public static Random random = new Random();
        public static string RandomUrl()
        {
            return string.Format("http://{0}.com", RandomString(6));
        }
        /// <summary>
        /// Randoms the string.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        public static string RandomString(int size)
        {
            var builder = new StringBuilder();
            char ch;

            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }

            return builder.ToString();
        }
}

Related Tutorials