| //以下代码实现---产生20个不同的随机数,存储到rands数组中!
int[] rands = new int[20]; int values,count,k; values=0; count=0; k=0; bool ys=true; for(int i=0;i<rands.Length;i++) { rands[i]=0; } while(ys) { Random ra=new Random(); values=ra.Next(1,21); for(int i=0;i<rands.Length;i++) { if(values==rands[i]) { count=count+1; } } if(count==0) { rands[k]=values; k=k+1; } count=0; if (k==20) { ys=false; }
根据需要改改就行! |