一,代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"---产生随机字符串---%@",[self generateTradeNO]);
}
//产生随机字符串
- (NSString *)generateTradeNO
{
static int kNumber = 15;
NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRST";
NSMutableString *resultStr = [[NSMutableString alloc] init];
srand(time(0));
for (int i = 0; i < kNumber; i++)
{
unsigned index = rand() % [sourceStr length];
NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
[resultStr appendString:oneStr];
}
return resultStr;
}
二,输出:
2015-10-23 10:04:22.908 产生随机字符串[974:46634] ---产生随机字符串---DQA5AGLNIBD52KQ