static void Main(string[] args)
{
const string cntA = "A";
const string cntB = "B";
const string cntC = "C";
const string cntD = "D";
int intA = 50;
int intB = 30;
int intC = 10;
int intD = 10;
string[] strArr = new string[4] { cntA, cntB, cntC, cntD };
int[] intCount = new int[4] { 0, 0, 0, 0 };
Random ran = new Random();
while (intCount[0] < intA || intCount[1] < intB || intCount[2] < intC || intCount[3] < intD)
{
int intIndex = ran.Next(0, 4);
string strCur = strArr[intIndex];
switch (strCur)
{
case cntA:
if (intCount[0] < intA)
{
intCount[0]++;
Console.Write(strCur);
}
break;
case cntB:
if (intCount[1] < intB)
{
intCount[1]++;
Console.Write(strCur);
}
break;
case cntC:
if (intCount[2] < intC)
{
intCount[2]++;
Console.Write(strCur);
}
break;
case cntD:
if (intCount[3] < intD)
{
intCount[3]++;
Console.Write(strCur);
}
break;
default:
break;
}
}
Console.WriteLine("随机生成完成!");
Console.WriteLine("A的总数:{0}", intCount[0]);
Console.WriteLine("B的总数:{0}", intCount[1]);
Console.WriteLine("C的总数:{0}", intCount[2]);
Console.WriteLine("D的总数:{0}", intCount[3]);
}