How can I generate 20 Uppercase characters randomly in my Objective-C iOS app?
NSMutableArray *a = [[NSMutableArray alloc] initWithObjects:@"A", @"B", @"C", @"D", @"E", nil]; // You can add more uppercases here.
int firstRandom = objectAtIndex:arc4random()%[a count];
NSString *s = [[NSString alloc] initWithFormat:@"%@", [a objectAtIndex:firstRandom]];
[a removeObjectAtIndex:firstRandom];
// Avoiding some uppercase repetitions. ;-)
for (int i = 0; i < [a count]; i++) {
int rndm = objectAtIndex:arc4random()%[a count];
s += [a objectAtIndex:rndm];
[a removeObjectAtIndex:rndm];
}
NSLog(@"%@", s);
[a release];
[s release];
Hope that answer this is what you want. :-)
Alberto