这个问题在这里已有答案:
我做了一些挖掘,我不相信这个问题已经回答了(尽管我会想象它会很简单)。
我想从数组中选择一个随机字符串。例如:
NSArray *strings = @[@"String1", @"String2", @"String3"];
NSString *randomString = // how to randomly select one of the three strings in the array?
你想要arc4random_uniform()
:
NSString *randomString = strings[arc4random_uniform(strings.count)];
更多信息在这个SO answer。