希望生成6位字符长度的UTF8随机字符串,如 9Xjkdt gyh廙
代码运行到x=0时崩溃(tp已等于6) 程序已预定义了中文字符生成,且在其它位置负责生成纯中文字符串的相似代码段运行正常
if (tp == 6)
{
//cout<< "yee";
int pos=0;
while(pos<6)
{
if(pos<=3 && pos%3==0)
{
int x=rnd() % 2;
if(x==1)
{
int y=rnd();
tmp[pos] = zmb[y];
pos+=1;
}
else
{
bool flag = 0;
while (!flag)
{
tmp[pos] = -23 - rnd() % 6;
tmp[pos + 1] = -65 - rnd() % 64;
tmp[pos + 2] = -65 - rnd() % 64;
if (tmp[pos] < -23 && tmp[pos] > -28)
flag = 1;
else if (tmp[pos] == -23 && (tmp[pos + 1] >= -65 || tmp[pos + 2] >= -81))
flag = 1;
else if (tmp[pos] == -28 && (tmp[pos + 1] >= -72))
flag = 1;
}
pos+=3;
//cout<< "yee";
}
}
else
{
//cout<< "yee";
int y=rnd();
tmp[pos] = zmb[y];
pos+=1;
}
}
}