首页 > 代码库 > C# 随机数生成避免重复

C# 随机数生成避免重复

  1. public string GetMsgID()
  2. {
  3. Random rand = new Random((int)DateTime.Now.Ticks);
  4. string szRand = rand.Next(0, 9999).ToString().PadLeft(4, ‘0‘);
  5. return string.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), szRand);
  6. }



null


C# 随机数生成避免重复