public static string Next(string chars, int length = 10) { ChoGuard.ArgumentNotNullOrEmpty(chars, "Chars"); if (length <= 0) { throw new ArgumentException("Length must be > 0."); } var random = new ChoCryptoRandom(); return(new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray())); }
public string ReplaceProperty(string propertyName, string format) { if (String.IsNullOrEmpty(propertyName)) { return(propertyName); } switch (propertyName) { case "APPLICATION_NAME": return(ChoUtility.Format(format, Process.GetCurrentProcess().ProcessName)); case "PROCESS_ID": return(ChoUtility.Format(format, Process.GetCurrentProcess().Id)); case "THREAD_ID": return(ChoUtility.Format(format, Thread.CurrentThread.ManagedThreadId)); case "THREAD_NAME": return(ChoUtility.Format(format, Thread.CurrentThread.Name)); case "RANDOM_NO": ChoCryptoRandom rnd = new ChoCryptoRandom(); return(ChoUtility.Format(format, rnd.Next())); case "TODAY": if (String.IsNullOrEmpty(format)) { return(GetTodaysDate().ToShortDateString()); } else { return(ChoUtility.Format(format, GetTodaysDate())); } case "NOW": if (String.IsNullOrEmpty(format)) { return(GetNowTime().ToShortTimeString()); } else { return(ChoUtility.Format(format, GetNowTime())); } default: return(ResolveNGetPropetyValue(format, propertyName)); } }
public static int Next(int minValue, int maxValue) { ChoCryptoRandom random = new ChoCryptoRandom(); return(random.Next(minValue, maxValue)); }
public static double Next(double minValue, double maxValue) { ChoCryptoRandom random = new ChoCryptoRandom(); return(random.NextDouble() * (maxValue - minValue) + minValue); }