I want to take 4 random numbers and save it into an NSSet
( to ensure that same number is not in the array)
As the int
values has to be NSNumber
object and hence cannot compare, it is not able to save unique integer in array.
+(NSMutableSet *)uniquenumber
{
int j=0;
NSMutableSet *sets=[[NSMutableSet alloc]init];
while (sets.count<4) {
j=arc4random()%7;
[sets addObject:[NSNumber numberWithInteger:j]];
}
return sets;
}
I want to get 4 unique number randomly from 0-7
. Thats the problem.
Appreciate your help and suggestions to improve the code.