这就是我想要做的。每次我的 viewDidLoad 启动时获取 7 个随机的、非重复的数字。我得到它来创建随机数,但我一直试图在加载 NSMutableSet 以获取新集合时清除它,但我遇到了麻烦。NSLog 清楚地显示 NSMutableSet 中没有任何内容,但它总是以相同的顺序出现相同的数字?
// Create set
NSMutableSet *mySet = [NSMutableSet setWithCapacity:6];
// Clear set
NSMutableSet *mutableSet = [NSMutableSet setWithSet:mySet];
[mutableSet removeAllObjects];
mySet = mutableSet;
NSLog(@"mutableSet: %@", mutableSet); // Shows nothing
NSLog(@"mySet: %@", mySet); // Shows nothing
// Assign random numbers to the set
while([mySet count]<=6){
int Randnum = arc4random() % 7+1;
[mySet addObject:[NSNumber numberWithInt:Randnum]];
}
NSLog(@"mySet1: %@", mySet); // Always shows 5,1,6,2,7,3,4 ???