随机函数
在c#中的随机函数是哪个,怎么使用?
------解决方案--------------------Random rand = new Random();
int i = rand.Next(100);
------解决方案--------------------public string GetByRndNum()
{
string Vchar = "0,1,2,3,4,5,6,7,8,9 ";//,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,x,y,z " ;
string[] VcArray = Vchar.Split( ', ');
string VNum = " ";
//采用一个简单的算法以保证生成随机数的不同
Random rand = new Random();
int[] rndArr = new int[rndLength];
for (int i = 1; i < rndLength + 1; i++)
{
if(i> 1)
{
do
{
rndArr[i-1] = rand.Next(10);//rand.Next(35) ;
bool goon = false;
for(int ix=0; ix <i-1; ix++)
{
if (rndArr[ix] == rndArr[i-1])
{
goon = true;
break;
}
}
if (!goon)
break;
} while (1 == 1);
}
else
rndArr[i-1] = rand.Next(10);
VNum += rndArr[i-1];
}
return VNum;
}