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);

相关文章:

  • 2022-12-23
  • 2021-06-22
  • 2021-12-10
  • 2021-09-22
  • 2021-12-24
  • 2021-12-21
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-12-10
  • 2021-11-07
  • 2021-09-02
相关资源
相似解决方案