代码贴上:
#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
请按任意键继续. . .