110,533
社区成员
发帖
与我相关
我的任务
分享
int rand10()
{
return rand7()/2+rand7();
}
static Random rd = new Random();
static void Main(string[] args)
{
int[] result = new int[10];
for (int i = 0; i < 100000; i++)
{
int x = rand10();
result[x-1]++;
}
foreach (int times in result)
{
Console.WriteLine(times);
}
Console.ReadKey();
}
static int rand10()
{
int i = 7, x;
while (i == 7)
{
i = rand7();
}
if (i < 4)
{
x = 0;
}
else
{
x = 5;
}
i = 7;
while (i > 5)
{
i = rand7();
}
return x + i;
}
static int rand7()
{
return rd.Next(1,8);
}
static int Rand10()
{
double result;
result = Rand7() * 10 / 7;
return (int)Math.Floor(result);
}