身分證產生器
就符合身分證的編碼規則
其他好像也沒啥好多說的
只是剛好寫了就丟上來
void RandomID(char cZone_, int iMale_, char* acBuff_)
{
assert(iMale_<=2 && iMale_>=0);
srand(time(NULL));
int iZone;
char cChar;
if(cZone_>=65 && cZone_<=90)
{
iZone = arrZone[cZone_-65];
cChar = cZone_;
}
else if(cZone_>=97 && cZone_<=122)
{
iZone = arrZone[cZone_-97];
cChar = cZone_ - 32;
}
else if(cZone_==0)
{
int iran = rand()%26;
iZone = arrZone[iran];
cChar = iran+65;
}
else
assert(false);
int iMale;
if(iMale_==0)
iMale = (rand()%2)+1;
else
iMale = iMale_;
int arrayCode[10];
arrayCode[0] = iZone/10;
arrayCode[1] = iZone%10;
arrayCode[2] = iMale;
for(int i=3; i<10; i++)
arrayCode[i] = rand()%10;
int iSum = arrayCode[0];
for(int j=1; j<10; j++)
iSum += arrayCode[j] *(10-j);
int iCheck = (10- iSum%10)%10;
char acBuff[10+1];
acBuff[0] = cChar;
for(int k=1; k<9; k++)
acBuff[k] = arrayCode[k+1]+48;
acBuff[9] = iCheck + 48;
acBuff[10] = '\0';
::memcpy(acBuff_, acBuff, sizeof(acBuff));
}