关于产生不同的4个随机数
void RanNum(int randomNumber[4])
{
srand((unsigned)time(NULL));
for(int i = 0; i < 3; i++)
{
randomNumber[i] = rand() % 10;
while(randomNumber[0] == 0)
{
randomNumber[0] = rand() % 10;
}
while(randomNumber[i] == 10)
{
randomNumber[i] = rand() % 10;
}
for(int j = 0; j < i; j++)
{
while(randomNumber[j] == randomNumber[i])
{
randomNumber[i] = rand() % 10;
j = 0;
}
}
}
}
{
srand((unsigned)time(NULL));
for(int i = 0; i < 3; i++)
{
randomNumber[i] = rand() % 10;
while(randomNumber[0] == 0)
{
randomNumber[0] = rand() % 10;
}
while(randomNumber[i] == 10)
{
randomNumber[i] = rand() % 10;
}
for(int j = 0; j < i; j++)
{
while(randomNumber[j] == randomNumber[i])
{
randomNumber[i] = rand() % 10;
j = 0;
}
}
}
}
代码如上
但是有点问题:
1.0会重复出现 例如8090 8900,其他数字没有问题
2.最后一位一定是0