zoukankan      html  css  js  c++  java
  • C#随机数字生成的一种方法

    1、参考:

       public class RandomLongGenerater
        {
            public static long New(int bit)
            {
                if (bit > 16)
                {
                    throw new Exception("bit must <= 16");
                }
                if (bit < 6)
                {
                    throw new Exception("bit must >= 6");
                }
                string midStr = "";
                byte[] bytes = Guid.NewGuid().ToByteArray();
                for (int i = 0; i < bit; i++)
                {
                    midStr += bytes[i].ToString().Last<char>();
                }
                if (midStr[0] == '0')
                {
                    midStr = new Random().Next(1, 10).ToString() + midStr.Substring(1);
                }
                return long.Parse(midStr);
            }
            public static long New64Bit()
            {
                return New(16);
            }
            public static long New()
            {
                return New(9);
            }
    
        }

    2:调用:

    RandomLongGenerater.New(16);
  • 相关阅读:
    js中级-函数封装
    js中级-11.7
    js中级-11.5
    js中级-11.2
    js中级-this
    js中级-作用域链
    10.23
    10.22
    10.19js
    10.18
  • 原文地址:https://www.cnblogs.com/songxingzhu/p/5717924.html
Copyright © 2011-2022 走看看