随机生成中文代码Object-c

2017-11-24  本文已影响10人  跬步千里_LenSky

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);

上一篇下一篇

猜你喜欢

热点阅读