GUID获取16位19位22位的唯一字符串
/// <summary>
/// 根据guid获取16位的唯一字符串
/// </summary>
/// <param name=\"guid\"></param>
/// <returns></returns>
public static string guidto16string()
{
long i = 1;
foreach (byte b in guid.newguid().tobytearray())
i *= ((int)b + 1);
return string.format("{0:x}", i - datetime.now.ticks);
}
/// <summary>
/// 根据guid获取19位的唯一数字序列
/// </summary>
/// <returns></returns>
public static long guidtolongid()
{
byte[] buffer = guid.newguid().tobytearray();
return bitconverter.toint64(buffer, 0);
}
/// <summary>
/// 生成22位唯一的数字 并发可用
/// </summary>
/// <returns></returns>
public static string generateuniqueid()
{
system.threading.thread.sleep(1); //保证yyyymmddhhmmssffff唯一
random d = new random(bitconverter.toint32(guid.newguid().tobytearray(), 0));
string strunique = datetime.now.tostring("yyyymmddhhmmssffff") + d.next(1000, 9999);
return strunique;
}
上一篇: InnoSetup 使用