CSharp examples for System:Random
Random Password
using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w ww . ja va 2s . com public class Main{ public static string RandomPassword(int length) { var sb = new StringBuilder(); sb.Append("1"); sb.Append("A"); sb.Append("a"); sb.Append("!"); 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(); } }