长度100的随机数组,单个随机数小于等于100
C#写法:
public static void Main()
{
int[] intArr=new int[100];
ArrayList myList=new ArrayList();
Random rnd=new Random();
string sum="";
while(myList.Count<100)
{
int num=rnd.Next(1,101);
if(!myList.Contains(num))
myList.Add(num);
}
for(int i=0;i<100;i++)
{
intArr[i]=(int)myList[i];
sum +=intArr[i]+",";
}
sum = sum.Substring(0,sum.Length-1);
Console.Write("产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复:\n"+sum);
string[] s = sum.Split(',');
Console.Write("\n数组长度为:"+s.Length);
Console.ReadKey();
}