0的ascii为48,z的ascii为122,因此只要获得这段区间的字符判断是否为字符或数字就行了
代码如下:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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 ;
}