iOS 随机字符串

2022-09-19  本文已影响0人  _Waiting_
//产生length个长度随机字符串
- (NSString *)getRandStringWithLength:(int)length
{
    
    NSString *sourceStr = @"0123456789abcdefghijklmnopqrstuvwxyz";
    NSMutableString *resultStr = [[NSMutableString alloc] init];
    
    for (int i = 0; i < length; i++)
    {
        unsigned index = arc4random() % [sourceStr length];
        NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
        [resultStr appendString:oneStr];
        
    }
    return resultStr;
}
上一篇下一篇

猜你喜欢

热点阅读