Get random shorten URL
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Web; public class Utility { public static string GetRandomShortenUrl(int length) { if (length == -1) length = GetRandomNumber(2, 6); string charPool = "ABCDEFGOPQRSTUVWXY1234567890ZabcdefghijklmHIJKLMNnopqrstuvwxyz"; StringBuilder rs = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) { rs.Append(charPool[(int)(random.NextDouble() * charPool.Length)]); } return rs.ToString(); } public static int GetRandomNumber(int start, int end) { Random rand = new Random(); return rand.Next(start, end); } }