码迷,mamicode.com
首页 > 其他好文 > 详细

一个自动生成类似的GUID(无重复保障)

时间:2016-10-08 20:17:00      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

 1 public string GetRandStr()
 2         {
 3             System.Text.StringBuilder newRandom = new System.Text.StringBuilder(20);
 4             Random rd = new Random();
 5             char[] dptSysID = { ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘, ‘a‘, ‘c‘, ‘d‘, ‘e‘, ‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘ };
 6             for (int i = 0; i < 32; i++)
 7             {
 8                 newRandom.Append(dptSysID[rd.Next(20)]);
 9             }
10             string sysID = newRandom.ToString();
11             return sysID.Substring(0, 8).ToString() + "-"
12                  + sysID.Substring(8, 4).ToString() + "-"
13                  + sysID.Substring(12,4).ToString() + "-"
14                  + sysID.Substring(16,4).ToString() + "-"
15                  + sysID.Substring(20,12).ToString();
16         }

 

一个自动生成类似的GUID(无重复保障)

标签:

原文地址:http://www.cnblogs.com/mingsn/p/5939597.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!