随机生成中文代码Object-c

NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);

NSInteger randomH = 0xA1+arc4random()%(0xFE - 0xA1+1);

NSInteger randomL = 0xB0+arc4random()%(0xF7 - 0xB0+1);

NSInteger number = (randomH<<8)+randomL;

NSData *data = [NSData dataWithBytes:&number length:2];

NSString *string = [[NSString alloc] initWithData:data encoding:gbkEncoding];

NSLog(@"随机生成的文字---|%@",string);

你可能感兴趣的:(随机生成中文代码Object-c)