美文网首页
等长随机字符串生成(methodName)

等长随机字符串生成(methodName)

作者: 西博尔 | 来源:发表于2016-12-30 10:39 被阅读40次
- (NSString *)randomStr:(NSString *)methodName
{
    NSString *string = @"";
    NSString * newMethod = @"";
    if ([methodName rangeOfString:@":"].location != NSNotFound) {
        
        if ([methodName componentsSeparatedByString:@":"].count >= 2) {
            NSArray * array = [methodName componentsSeparatedByString:@":"];
            
            for (int i = 0; i < array.count; i++) {
                NSString * newStr = [self randomStr:array[i]];
                
                
                if (![newStr isEqualToString:@""] && newStr != nil) {
                    newMethod = [newMethod stringByAppendingFormat:@"%@:",newStr];
                }
                
                
            }
            return newMethod;
        }

    
    }
    else
    {
        for (int i = 0; i < methodName.length; i++) {
            int number = arc4random() % 36;
            if (number < 10) {
                int figure = arc4random() % 10;
                NSString *tempString = [NSString stringWithFormat:@"%d", figure];
                string = [string stringByAppendingString:tempString];
            }else {
                int figure = (arc4random() % 26) + 97;
                char character = figure;
                NSString *tempString = [NSString stringWithFormat:@"%c", character];
                string = [string stringByAppendingString:tempString];
            }
        }
    }
    
    
    return string;
}

相关文章

网友评论

      本文标题:等长随机字符串生成(methodName)

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