c#生成6个随机数,要求1到33之间不重复的随机数,要最简单的写法
2个回答
展开全部
int[] xl = new int();
int tmp = 0;
string output = "the numbers are: ";
Random rd = new Random();
//把1-33放在数组里
for (int i = 0; i < 33; i++)
{
xl[i] = i;
}
//循环6次
for (int i = 0; i < 6; i++)
{
//产生随机数
int id = rd.Next(33 - i);
output += xl[id - 1].ToString() + " ";
//交换位置
tmp = xl[id - 1];
xl[id - 1] = xl[33 - i];
xl[33 - i] = tmp;
}
return output;
int tmp = 0;
string output = "the numbers are: ";
Random rd = new Random();
//把1-33放在数组里
for (int i = 0; i < 33; i++)
{
xl[i] = i;
}
//循环6次
for (int i = 0; i < 6; i++)
{
//产生随机数
int id = rd.Next(33 - i);
output += xl[id - 1].ToString() + " ";
//交换位置
tmp = xl[id - 1];
xl[id - 1] = xl[33 - i];
xl[33 - i] = tmp;
}
return output;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询