本文介绍了强制随机播放NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为putNumberUsed的NSMutableArray.它包含以下对象@"blah1,@" blah2,@" blah3,@" blah4.我想随机地随机播放这些对象,例如,如果我选择:
I have a NSMutableArray called putNumberUsed. It contains the following objects @"blah1,@"blah2",@"blah3",@"blah4". I want to shuffle these objects randomly so for example if I chose:
[putNumberUsed objectAtIndex:0]
它会给我除"blah1"以外的任何东西.我将如何去做呢?以下是我到目前为止使用的代码:
it would give me anything but "blah1". How would I go about doing this? The following is the code I used thus far:
NSMutableArray *putNumbersUsed = [[NSMutableArray alloc] arrayWithObjects:@"blah1",@"blah2",@"blah3",@"blah4",nil];
推荐答案
我认为,您可以为此编写一个循环.请检查以下代码,
I think, You can write a loop for that. Please check the following code,
for (int i = 0; i < putNumberUsed.count; i++) {
int randomInt1 = arc4random() % [putNumberUsed count];
int randomInt2 = arc4random() % [putNumberUsed count];
[putNumberUsed exchangeObjectAtIndex:randomInt1 withObjectAtIndex:randomInt2];
}
这对您可能有用.
这篇关于强制随机播放NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!