1. //C++ 随机字符串生成函数
    2. #include<iostream>
    3. #include<ctime>
    4. using namespace std;
    5. const int LEN_NAME=4;
    6. char *rand_str(char *str,const int len)
    7. {
    8. int i;
    9. for(i=0;i<len;++i)
    10. str[i]='A'+rand()%26;
    11. str[++i]='\0';
    12. return str;
    13. }
    14. void main()
    15. {
    16. srand(time(NULL));
    17. int i;
    18. char name[LEN_NAME+1];
    19. for(i=0;i<20;++i)
    20. {
    21. cout<<rand_str(name,LEN_NAME)<<endl;
    22. }
    23. }