请教大神如何让一个4*4矩阵里的数重新随机分布。
我目前同过函数得到了两组相同的数在一个4*4的数组里,我想让里面的数重新随机分布,但是具体的数是不变化的,我该怎么做,谢谢。#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int a[20];
int a1[4][4];
int a2[4][4];
int i, j;
int m, n;
srand((int)time(0));
a[0] = rand() % 20 + 1;
for (i = 1; i<20; i++)
{
a[i] = rand() % 20 + 1;
for (j = 0; j<i; j++)
{
if (a[i] == a[j])
{
i--;
}
}
}
for (m = 0,i=0; m < 4;m++,i=i+4)
{
a1[m][0] = a[i];
a1[m][1] = a[i+1];
a1[m][2] = a[i+2];
a1[m][3] = a[i+ 3];
}
for (m = 2,i=0; m < 4;m++,i=i+4)
{
a1[m][0] = a[i];
a1[m][1] = a[i + 1];
a1[m][2] = a[i + 2];
a1[m][3] = a[i + 3];
}
printf("%d %d %d %d\n\n", a1[0][0], a1[0][1], a1[0][2], a1[0][3]);
printf("%d %d %d %d\n\n", a1[1][0], a1[1][1], a1[1][2], a1[1][3]);
printf("%d %d %d %d\n\n", a1[2][0], a1[2][1], a1[2][2], a1[2][3]);
printf("%d %d %d %d\n\n", a1[3][0], a1[3][1], a1[3][2], a1[3][3]);
}