随机洗牌
我最近在制作时遇到了麻烦:
- 我创建了一个 randomization_array ,我导入了所有 8 个 图像....
- 我创建了一个包含 8 个图像的数据 plist(NSDictionary)
然后,
NSMutableArray *randomization_array = [[NSMutableArray alloc] init]; [randomization_array addObjectsFromArray:array]; [randomization_array addObjectsFromArray:array]; NSMutableArray *shuffled_array = [[NSMutableArray alloc] initWithArray:randomization_array]; for(int x=0;x<[随机化数组计数]/2;x++) { int random = arc4random_uniform([randomization_array count] / 2 ); int 目的地 = 随机 *2; NSDictionary *origin_dict = [randomization_array objectAtIndex:x]; NSDictionary *destination_dict= [randomization_array objectAtIndex:destination]; [shuffled_array insertObject:origin_dict atIndex:destination]; [shuffled_array insertObject:destination_dict atIndex:x]; }
我将其设为 2 组随机图像...
我的问题,如何我应该每次只制作两组图像吗... 我随机播放图像应该成对 8+8=16....期待 对于代码朋友
I recently had trouble of making:
- i created an randomization_array which i import all of my 8
images.... - i created an data plist of 8 images(NSDictionary)
then,
NSMutableArray *randomization_array = [[NSMutableArray alloc] init]; [randomization_array addObjectsFromArray:array]; [randomization_array addObjectsFromArray:array]; NSMutableArray *shuffled_array = [[NSMutableArray alloc] initWithArray:randomization_array]; for(int x=0;x<[randomization_array count]/2;x++) { int random = arc4random_uniform([randomization_array count] / 2 ); int destination = random *2; NSDictionary *origin_dict = [randomization_array objectAtIndex:x]; NSDictionary *destionation_dict= [randomization_array objectAtIndex:destination]; [shuffled_array insertObject:origin_dict atIndex:destination]; [shuffled_array insertObject:destionation_dict atIndex:x]; }
i make it 2 set of the random images....
my question,how should i make only two set of images.... every time
i shuffle the images should come in pair 8+8=16....looking forward
to the codes frens
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,我已使用 AQGRIDVIEW 在随机化和网格视图中进行随机洗牌,请参考此内容并使用此实现。下面是链接下载代码并使用此
https://github.com/sync/AQGridView
快乐编码:)
hello i have used for random shuffle in randomize and grid view usig the AQGRIDVIEW pls refer this and implement using this .below is link download code and use this
https://github.com/sync/AQGridView
Happy coding :)