产生随机不重复ID

 /// <summary>
/// Decimal 27位ID生成规则(前面17位为时间,后面10位为随机生成数):
/// </summary>
/// <returns></returns>
public decimal GeneratePk()
{
Guid id = Guid.NewGuid();
byte[] byid = id.ToByteArray();

uint uid = BitConverter.ToUInt32(byid, 12);
string strid = DateTime.Now.ToString("yyyyMMddHHmmssfff") + uid.ToString("D10");

return decimal.Parse(strid);
}

 

posted @ 2012-03-22 15:52  小罗》  阅读(471)  评论(0编辑  收藏  举报