代码
WCHAR tmpKeyCode[17] = {0};
srand(GetTickCount());//设置种子
for( int j = 0 ; j < 16 ; j++ ){
tmpKeyCode[j] = code[ rand()%15 ];
}
randCode.Format(L"%s",tmpKeyCode);
AfxMessageBox(randCode);
srand(GetTickCount());//设置种子
for( int j = 0 ; j < 16 ; j++ ){
tmpKeyCode[j] = code[ rand()%15 ];
}
randCode.Format(L"%s",tmpKeyCode);
AfxMessageBox(randCode);
要设置种子不然每次取出的随机数都一样,windows下可以用 srand(time(NULL)); wince 用 srand(GetTickCount());