主题:为何这个契约棋牌中的随机数分配有重复
请各位高手帮我看看这个程序为何输出结果在1至52之间有重复啊
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void sortary(int oary[]);
void giveary(int ary[],int ary1[],int ary2[],int ary3[],int ary4[]);
void printary(int oary[]);
int main (void)
{
int ary[52];
int ary1[13];
int ary2[13];
int ary3[13];
int ary4[13];
int i;
srand((unsigned)time(NULL));
for(i=0;i<52;i++)
ary[i]=rand()%52+1;
giveary(ary,ary1,ary2,ary3,ary4);
sortary(ary1);
sortary(ary2);
sortary(ary3);
sortary(ary4);
printf("\nNORTH\n");
printary(ary1);
printf("\nEAST\n");
printary(ary2);
printf("\nSOUTH\n");
printary(ary3);
printf("\nWEST\n");
printary(ary4);
return 0;
}
void giveary(int ary[],int ary1[],int ary2[],int ary3[],int ary4[])
{
int i;
int m;
for(i=0;i<13;i++)
ary1[i]=ary[i];
for(i=13;i<26;i++)
{
m=i-13;
ary2[m]=ary[i];
}
for(i=26;i<39;i++)
{
m=i-26;
ary3[m]=ary[i];
}
for(i=39;i<52;i++)
{
m=i-39;
ary4[m]=ary[i];
}
return;
}
void sortary(int oary[])
{
int i;
int current;
int temp;
int smallest;
for(smallest=0;smallest<12;smallest++)
for(current=smallest+1;current<13;current++)
if(oary[current]<oary[smallest])
{
temp=oary[current];
oary[current]=oary[smallest];
oary[smallest]=temp;
}
return;
}
void printary(int oary[])
{
int i;
for(i=0;i<13;i++)
printf("%3d",oary[i]);
printf("\n");
return;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void sortary(int oary[]);
void giveary(int ary[],int ary1[],int ary2[],int ary3[],int ary4[]);
void printary(int oary[]);
int main (void)
{
int ary[52];
int ary1[13];
int ary2[13];
int ary3[13];
int ary4[13];
int i;
srand((unsigned)time(NULL));
for(i=0;i<52;i++)
ary[i]=rand()%52+1;
giveary(ary,ary1,ary2,ary3,ary4);
sortary(ary1);
sortary(ary2);
sortary(ary3);
sortary(ary4);
printf("\nNORTH\n");
printary(ary1);
printf("\nEAST\n");
printary(ary2);
printf("\nSOUTH\n");
printary(ary3);
printf("\nWEST\n");
printary(ary4);
return 0;
}
void giveary(int ary[],int ary1[],int ary2[],int ary3[],int ary4[])
{
int i;
int m;
for(i=0;i<13;i++)
ary1[i]=ary[i];
for(i=13;i<26;i++)
{
m=i-13;
ary2[m]=ary[i];
}
for(i=26;i<39;i++)
{
m=i-26;
ary3[m]=ary[i];
}
for(i=39;i<52;i++)
{
m=i-39;
ary4[m]=ary[i];
}
return;
}
void sortary(int oary[])
{
int i;
int current;
int temp;
int smallest;
for(smallest=0;smallest<12;smallest++)
for(current=smallest+1;current<13;current++)
if(oary[current]<oary[smallest])
{
temp=oary[current];
oary[current]=oary[smallest];
oary[smallest]=temp;
}
return;
}
void printary(int oary[])
{
int i;
for(i=0;i<13;i++)
printf("%3d",oary[i]);
printf("\n");
return;
}