随机字符串生成

来源:互联网 发布:淘宝一分钱壁纸类目 编辑:程序博客网 时间:2024/04/27 04:36
#include <iostream>
#include <CTIME>
using std::cout;

const int SIZE_CHAR = 32;  //生成32 + 1位C Style字符串

const char CCH[] = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";

int main()
{
    srand((unsigned)time(NULL));

    char ch[SIZE_CHAR + 1] = {0};

    for (int i = 0; i < SIZE_CHAR; ++i)
    {
        int x = rand() % (sizeof(CCH) - 1);  
        
        ch[i] = CCH[x];
    }

    cout <<ch <<"/n";        

    return 0;
原创粉丝点击