0的ascii为48,z的ascii为122,因此只要获得这段区间的字符判断是否为字符或数字就行了
代码如下:
代码
CString GenerateRandomStr( void )
{
char *output = new char[33]; //修改这里可以改变生成的字符串长度,下面要同时修改哦
srand( (unsigned)time( NULL ) );
char c;
for( int a = 0; a < 33; a++ ) {
c = ( (rand() % 74) + 48 );
while( !IsCharAlphaNumeric( c ) ) {
c = ( (rand() % 74) + 48 );
}
output[ a ] = c;
}
output[ 33 ] = '\0';
CString out(output);
return out;
}
{
char *output = new char[33]; //修改这里可以改变生成的字符串长度,下面要同时修改哦
srand( (unsigned)time( NULL ) );
char c;
for( int a = 0; a < 33; a++ ) {
c = ( (rand() % 74) + 48 );
while( !IsCharAlphaNumeric( c ) ) {
c = ( (rand() % 74) + 48 );
}
output[ a ] = c;
}
output[ 33 ] = '\0';
CString out(output);
return out;
}