//#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <Windows.h>
using namespace std;
class Random_Chinese
{
public:
string Rand_Chinese()
{
srand(unsigned(clock() * (time(NULL)))); //产生毫秒随机数(利用clock函数将时间转换为毫秒单位)
Sleep(1); //试试注释一下你就懂了
rand1 = 0xf7 - 0xb0;
rand2 = 0xfe - 0xa1;
byte1 = rand() % rand1 + 0xb0;
byte2 = rand() % rand2 + 0xa1;
str = byte1;
str += byte2;
return str; //返回随机汉字
}
private:
string str;
BYTE byte1, byte2;
int rand1;
int rand2;
};
int main()
{
string name;
Random_Chinese r1;
for (int i = 0; i < 10; i++)
{
name = r1.Rand_Chinese();
cout << name << endl;
}
return 0;
}
C++面向对象 随机汉字
最新推荐文章于 2023-05-31 16:03:04 发布