- (nsstrings *) getRandomWord: (int) count {
Int nextNum=1;
NSStringEncoding gbkEncoding=CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000);
Init nsstrings * result=[[nsstrings alloc]].
for (int i=0; I & lt; The count. I++) {
@ autoreleasepool {
//[random number between 0 and 100)
NextNum=arc4random () % 100;
If (nextNum % 4==0) {
Int heightPos=176 + arc4random () % 39;
Int lowPos=161 + arc4random () % 93;
Byte wordBytes [2]={(Byte) heightPos, (Byte) lowPos};
Nsstrings * oneWord=[[nsstrings alloc] initWithBytes: wordBytes length: 2 encoding: gbkEncoding];
Result=[result stringByAppendingString: oneWord];
} else if (nextNum % 4==1) {
Char c=65 + arc4random () % 26;
Result=[result stringByAppendingFormat: @ "% c", c];
} else if (nextNum % 4==2) {
Char c=97 + arc4random () % 26;
Result=[result stringByAppendingFormat: @ "% c", c];
} else {
Int num=1 + arc4random () % 10;
Result=[result stringByAppendingFormat: @ "% d", num];
}
}
}
return result;
}
CodePudding user response:
The