美文网首页
iOS 生成字母和数字的随机数

iOS 生成字母和数字的随机数

作者: 橙_知足常乐 | 来源:发表于2022-10-10 11:57 被阅读0次
    - (NSString *)getRandomStringWithNum:(NSInteger)num
    {
        NSString *string = [[NSString alloc]init];
        for (int i = 0; i < num; 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;
    }
    

    相关文章

      网友评论

          本文标题:iOS 生成字母和数字的随机数

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