美文网首页
iOS 随机字符串

iOS 随机字符串

作者: _Waiting_ | 来源:发表于2022-09-19 16:08 被阅读0次
    //产生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;
    }
    

    相关文章

      网友评论

          本文标题:iOS 随机字符串

          本文链接:https://www.haomeiwen.com/subject/lyuportx.html