产生100以内的不重复随机数
static
void
Main(
string
[] args)
{
int [] n100 = new int [ 100 ];
ArrayList _n100 = new ArrayList();
Random random = new Random();
for ( int i = 0 ; i < 100 ; i ++ )
{
_n100.Add(i);
}
for ( int i = 99 ; i > - 1 ; i -- )
{
int a = Math.Abs(random.Next(i));
n100[i] = ( int )_n100[a];
_n100.RemoveAt(a);
Console.WriteLine( " n100[{0}]:{1} a={2} " , i, n100[i],a);
}
}
{
int [] n100 = new int [ 100 ];
ArrayList _n100 = new ArrayList();
Random random = new Random();
for ( int i = 0 ; i < 100 ; i ++ )
{
_n100.Add(i);
}
for ( int i = 99 ; i > - 1 ; i -- )
{
int a = Math.Abs(random.Next(i));
n100[i] = ( int )_n100[a];
_n100.RemoveAt(a);
Console.WriteLine( " n100[{0}]:{1} a={2} " , i, n100[i],a);
}
}