using System; using System.Diagnostics; namespace BF { internal class NetUtility { internal static int getNewSeed() { byte[] rndBytes = new byte[4]; System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); rng.GetBytes(rndBytes); return BitConverter.ToInt32(rndBytes, 0); } internal static string GetRandomString(int len) { string s = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; string reValue = string.Empty; Random rnd = new Random(getNewSeed()); while (reValue.Length < len) { string s1 = s[rnd.Next(0, s.Length)].ToString(); if (reValue.IndexOf(s1) == -1) reValue += s1; } return reValue; } } internal static class NetTime { private static readonly long epoch = new DateTime(1970, 1,1,0,0,0,DateTimeKind.Utc).Ticks; private static readonly long timeInitialized = Stopwatch.GetTimestamp(); private static readonly double InvFreq = 1.0 / (double)Stopwatch.Frequency; /// /// get seconds since application start /// public static double Now => (Stopwatch.GetTimestamp() - timeInitialized) * InvFreq; /// /// ms /// /// public static long ClientNow() { return (DateTime.UtcNow.Ticks - epoch) / 10000; } /// /// s /// /// public static long ClientNowSeconds() { return (DateTime.UtcNow.Ticks - epoch) / 10000000; } } }