Iphone SIGABRT错误和应用程序崩溃

Iphone SIGABRT错误和应用程序崩溃,iphone,Iphone,这是我的代码,我从中得到SIGABRT错误 p3=@"0123456789"; [password appendFormat: @"%C", [p3 characterAtIndex: arc4random() % [p3 length]]]; 如何解决这个问题 p3=@"0123456789"; [password appendFormat: @"%C", [p3 characterAtIndex: arc4random() % ([p3 length]-1])]; 看起来您超出了索引数组

这是我的代码,我从中得到
SIGABRT错误

p3=@"0123456789";
[password appendFormat: @"%C", [p3 characterAtIndex: arc4random() % [p3 length]]];
如何解决这个问题

p3=@"0123456789";
[password appendFormat: @"%C", [p3 characterAtIndex: arc4random() % ([p3 length]-1])];

看起来您超出了索引数组的范围,从0开始。Ad为-1。

当随机数为0时,索引将是字符串的长度,这超出了限制。因此jst使用一个较小的长度作为
index=arc4random()%([str length]-1;
尝试以下方法:

    NSString *p3=@"0123456789"; 
    int t = arc4random() % [p3 length];
    NSLog(@"%@",[p3 substringWithRange:NSMakeRange(t, 1)]);

    NSMutableString * password = [[NSMutableString alloc] init];
    [password appendFormat:[NSString stringWithFormat:@"%@",[p3 substringWithRange:NSMakeRange(t, 1)]]];

什么是密码?NSString?这是Mac OSX应用程序吗?因为arc4random()在Mac OSX库中!好的,从你的评论中可以看出这是iOS应用程序。但是,
arc4random()
?为什么要使用它?我想从字符串p3生成随机字符