Hi
I'm trying to compare a random number to an Array.
If the number is not in the Array, NSLog will tell me and write it to that array.
If the number is in the Array, I want it to generate a new random number and check that.
I will add code later so when the Array count hits 100, it will empty the array, that way it won't fill up.
Or any other suggestions on how to solve this would be good.
thank you
here's the method:
-(IBAction)myActionid)sender{
srandom(time(NULL));
int i = random() % 50 +1;
NSString *myString = [[NSString alloc] initWithFormat"%i", i];
if ([arr1 containsObject:myString] != YES) {
NSLog(@"Array count = %i", [arr1 count]);
NSLog(@"No, arr1 did not contain '%@', adding it now.", myString);
[arr1 addObject:myString ];
}
else {
//The random number i is already in the array, so I
//want it to generate new i and run the "if" again.
//Running another if here would not help, if the new value
//of i is in the array it would mean same problem all over again.
}
[myString release];
[arr1 retain];
NSLog(@"%@", arr1);
}
I'm trying to compare a random number to an Array.
If the number is not in the Array, NSLog will tell me and write it to that array.
If the number is in the Array, I want it to generate a new random number and check that.
I will add code later so when the Array count hits 100, it will empty the array, that way it won't fill up.
Or any other suggestions on how to solve this would be good.
thank you
here's the method:
-(IBAction)myActionid)sender{
srandom(time(NULL));
int i = random() % 50 +1;
NSString *myString = [[NSString alloc] initWithFormat"%i", i];
if ([arr1 containsObject:myString] != YES) {
NSLog(@"Array count = %i", [arr1 count]);
NSLog(@"No, arr1 did not contain '%@', adding it now.", myString);
[arr1 addObject:myString ];
}
else {
//The random number i is already in the array, so I
//want it to generate new i and run the "if" again.
//Running another if here would not help, if the new value
//of i is in the array it would mean same problem all over again.
}
[myString release];
[arr1 retain];
NSLog(@"%@", arr1);
}