我正在研究一个目前处于控制台应用阶段的夹具程序。我安排团队感谢所有人:)但我无法组织团队互相玩耍的日子。所以我创建了一个名为DaysReprep的数组,其中包含4个元素,它们代表星期几。(即0代表星期一,4代表星期五,5代表星期六,6代表星期日,哪些团队可以在这些天进行比赛。)我还创建了一个名为dayCounts的数组,用于保存随机创建的次数。我想随机选择它们,但是当0随机选择时,我不希望它再次随机创建。就像那样,我想随机生成1次3次(不连续),2次4次(不连续),3次1次。
这是我的代码和输出, 任何帮助,将不胜感激。
int[] daysReprep = new int[4] { 0, 4, 5, 6 }; //holds the representation of days(0-monday,4-friday,5-saturday,6-sunday)
int RandomChosenDay; //random value
int[] dayCounters = new int[4]; //which counts which element of the daysReprep array generated by RandomChosenDay(0.element holds 0.element of daysReprep and goes so on.)
for (int i = 0; i < weeklyMatched.GetLength(1); i++)
{
RandomChosenDay = randomNum.Next(3);
switch (RandomChosenDay)
{
case 0:
if (dayCounters[0] != 1)
{
dayCounters[0]++;
break;
}
else {
RandomChosenDay = randomNum.Next(3);
}
break;
case 1:
if (dayCounters[1] != 3)
{
dayCounters[1]++;
break;
}
else {
RandomChosenDay=randomNum.Next(3);
}
break;
case 2:
if (dayCounters[2] != 4)
{
dayCounters[2]++;
break;
}
else {
RandomChosenDay = randomNum.Next(3);
}
break;
case 3:
if (dayCounters[3] != 1)
{
dayCounters[3]++;
break;
}
else {
RandomChosenDay = randomNum.Next(3);
}
break;
}
for(int a = 0; a < daysReprep.Length; a++) //Writes the elemts of the dayCounters
{
Console.WriteLine(dayCounters[a] + " ");
}