随机数不重复 [英] Random number without repeating
本文介绍了随机数不重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有NSMutableArray,有50个数组元素。我需要随机生成而不重复。你能建议一些示例代码。
I have NSMutableArray with 50 array elements. I need to generate randomly without any repetition. Can you suggest some sample codes.
推荐答案
这里有一个示例来获得小于1000的随机int。
here is sample to get random int less than 1000.
int y = arc4random() % 1000;
保持不重复,只需在插入前检查
to stay without duplicates, just check before inserting
这篇关于随机数不重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文