代码可运行
void Random() //取随机数row、col
{
u8 j;
num = 0;
if(num == 0)
{
row = rand()%8;
col = rand()%8;
Randnum[0] = 10*row+col;
}
while(num > 0 && num < 64)
{
row = rand()%8;
col = rand()%8;
for(j=0;j<num;j++)
{
if(Randnum[j] == 10*row+col) randflag = 1;
if(Randnum[j] != 10*row+col) randflag = 0;
if(randflag == 1)
{
row = rand()%8;
col = rand()%8;
}
if(randflag == 0) Randnum[num] = 10*row+col;
}
}
if(num == 63) num = -1;
}
void Int0() interrupt 0 //外部中断 0 的中断函数
{
delay(1000); //延时消抖
if(k3 == 0)
{
delay(1000);
num = num + 1;
Random();
}
}
产生的不是严格意义上真正的随机数