//以下代码实现---产生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; }根据需要改改就行!
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18