写的一个模拟生成序列号的程序,有什么更好的方法写出更好的程序?
#include<stdio.h>#include<time.h>
#include<stdlib.h>
main()
{
int i,j,lep,leg;
int count=0;
int nut=0;
char ch;
char str[7][10]={"abcdefghi","jklmnopqr","stuvwxyz","ABCDEFGHI","JKLMNOPQR","STUVWXYZ0","123456789"};
srand((unsigned)time(NULL));
for(i=0;i<7;i++)
{
for(j=0;j<10;j++)
{
lep=rand()%10;
leg=rand()%7;
ch=str[i][lep];
str[i][lep]=str[leg][j];
str[leg][j]=ch;
}
}
while(1)
{
nut=0;
while(1)
{
lep=rand()%10;
leg=rand()%7;
if(str[leg][lep]!=' ' && str[leg][lep]!='\0')
{
printf("%c",str[leg][lep]);
nut++;
}
if(nut==4)break;
}
++count;
if(count!=4)
{
printf("-");
}
if(count==4)
{
break;
}
}
printf("\n");
}