标签:
/// <summary>
/// 根据日期和随机码生成订单号
/// </summary>
/// <returns></returns>
public string GetOrderNumber()
{
string num = DateTime.Now.ToString("yyMMddHHmmss");//yyyyMMddHHmmssms
return num + Number(2, false).ToString();
}
/// <summary>
/// 生成随机数字
/// </summary>
/// <param name="Length">生成长度</param>
/// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param>
/// <returns></returns>
public string Number(int Length, bool Sleep)
{
if (Sleep)
System.Threading.Thread.Sleep(3);
string result = "";
System.Random random = new Random();
for (int i = 0; i < Length; i++)
{
result += random.Next(10).ToString();
}
return result;
}
标签:
原文地址:http://www.cnblogs.com/sunzhenyong/p/4389102.html