Random Email - CSharp System

CSharp examples for System:Random

Description

Random Email

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from w  w w  .j  ava2 s .c o m*/

public class Main{
        public static string RandomEmail()
        {
            var sb = new StringBuilder();

            sb.Append(DataHelper.RandomString(10));
            sb.Append("@");
            sb.Append(DataHelper.RandomString(20));
            sb.Append(".com");

            return sb.ToString();
        }
        public static string RandomString(int length)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < length; i++)
            {
                sb.Append(
                    Convert.ToChar(Convert.ToInt32(Math.Floor((26 * DataHelper.Random.NextDouble()) + 65))));
            }

            if (sb.Length > 10)
            {
                sb.Append(DateTime.Now.ToString("hhMMssffff"));
                sb.Remove(0, 10);
            }
            else if (sb.Length > 6)
            {
                sb.Append(DateTime.Now.ToString("hhMMss"));
                sb.Remove(0, 6);
            }

            return sb.ToString();
        }
}

Related Tutorials