您的位置:首页 > 其它

产生随机字符数组的一种方法

2011-04-14 17:12 218 查看
代码贴上:

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <iostream>

// using namespace std;

int main()
{
const char *c = "0123456789abcdefghijklmnopqrstuvwxyz";

srand(static_cast<unsigned int>(time(NULL)));
std::cout << "The random char array is:";
for(int i = 0; i < 5; ++i)
{
std::cout << std::endl;
int index = 0 ;
for(int j = 0; j < 5; ++j)
{
index = rand() % strlen(c);
std::cout << c[index ]
<< c[index]
<< " ";
}
}
std::cout << std::endl;
return 0;
}


运行效果如下:

The random char array is:
00 qq 88 ii zz
qq bb oo 00 yy
rr yy tt ww ll
ss rr aa bb oo
11 yy tt 33 uu
请按任意键继续. . .
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐