std :: string GenRandomString ( int len) { std :: string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ; std :: string result; int l = str.length(); srand(time( NULL )); for ( int i = 0 ; i < len; i++) { result += str[rand() % l]; return result; int main () { int len = 10 ; std :: cout << GenRandomString(len) << std :: endl ; return 0 ;

该代码将生成一个指定长度的随机字符串。

  •