Posted on 2008-03-08 08:30
玄铁剑 阅读(541)
评论(0) 编辑 收藏 引用 所属分类:
asp.net 、
C# Winform
static public int GetSeed()
{
int iSeed = 0;
byte[] idArray = Guid.NewGuid().ToByteArray();
int id1, id2, id3, id4;
id1 = id2 = id3 = id4 = 0;
id1 |= (int)idArray[0];
id1 |= (int)idArray[1] << 8;
id1 |= (int)idArray[2] << 16;
id1 |= (int)idArray[3] << 24;
id2 |= (int)idArray[4];
id2 |= (int)idArray[5] << 8;
id2 |= (int)idArray[6] << 16;
id2 |= (int)idArray[7] << 24;
id3 |= (int)idArray[8];
id3 |= (int)idArray[9] << 8;
id3 |= (int)idArray[10] << 16;
id3 |= (int)idArray[11] << 24;
id4 |= (int)idArray[12];
id4 |= (int)idArray[13] << 8;
id4 |= (int)idArray[14] << 16;
id4 |= (int)idArray[15] << 24;
iSeed = id1 ^ id2 ^ id3 ^ id4;
return iSeed;
}
static int GetRandomSeed( )
{
byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider( );
rng.GetBytes( bytes );
return BitConverter.ToInt32( bytes , 0 );
}