zoukankan      html  css  js  c++  java
  • 生成唯一码

            /// <summary>
            /// 根据年月日+随机数获取19位的数据序列
            /// </summary>
            public static long GetRandomID
            {
                get
                {
                    Random random = new Random(Guid.NewGuid().GetHashCode());
                    return long.Parse(DateTime.Now.ToString("yyMMddHHmmssff") + random.Next(10000, 99999).ToString());
                }
            }

            /// <summary>
            /// 根据年月日+随机数获取19位的数据序列
            /// </summary>
            public static long GetHashCodeID
            {
                get
                {
                    var r = new Random(Guid.NewGuid().GetHashCode()).Next(0, 9999);
                    var s = Guid.NewGuid().GetHashCode().ToString().Replace("-", string.Empty) + r;
                    if (s.Length > 13)
                    {
                        s = s.Substring(0, 13);
                    }
                    var num = 19 - s.Length;
                    var f = DateTime.Now.ToString("yyMMddHHmmssffff").Substring(0, num) + s;
                    return long.Parse(f);
                }
            }

            /// <summary>  
            /// 根据GUID获取16位的唯一字符串  
            /// </summary>  
            /// <param name="guid"></param>  
            /// <returns></returns>  
            public static string GuidTo16String()
            {
                long i = 1;
                foreach (byte b in Guid.NewGuid().ToByteArray())
                    i *= ((int)b + 1);
                return string.Format("{0:x}", i - DateTime.Now.Ticks);
            }
            /// <summary>  
            /// 根据GUID获取19位的唯一数字序列  
            /// </summary>  
            /// <returns></returns>  
            public static long GuidToLongID()
            {
                byte[] buffer = Guid.NewGuid().ToByteArray();
                return BitConverter.ToInt64(buffer, 0);
            }

            /// <summary>
            /// 生成8为登录帐号
            /// </summary>
            public static string GetLoginCode
            {
                get
                {
                    Random random = new Random(Guid.NewGuid().GetHashCode());
                    return random.Next(10000000, 99999999).ToString();
                }
            }
    
    
    

    北清论文网-中国领先的应届毕业生论文网站

    北清论文网】【我要毕业啦论文网

  • 相关阅读:
    gcc -I -L -l区别
    如何在LINUX中开机、登陆、退出、定时、定期自动运行程序
    4B/5B编码原理
    powerpc平台移植zebra或quagga-0.99.23
    ubuntu 命令配置ip 网关 dns
    ubuntu新机安装工具
    svn add --no-ignore
    SSL handshake failed: SSL error: Key usage violation in certificate has been detected.
    netif_start_queue/netif_wake_queue/netif_stop_queue
    Linux系统中提示/usr/bin/ld: cannot find -lxxx错误的通用解决方法
  • 原文地址:https://www.cnblogs.com/jfeng/p/5523959.html
Copyright © 2011-2022 走看看