也许你想要更随机和更有未来的证据:-)
NSString *username = [[GKLocalPlayer localPlayer] alias];
int text = arc4random_uniform(4); //Don't do this: rand() % val or arc4random() % val
switch (text) {
case 0: mainTextController.text = [NSString stringWithFormat:@"%@ %@ ",username,@"LEOONS"]; break;
case 1: mainTextController.text = [NSString stringWithFormat:@"%@ %@ ",username,@"AAIING"]; break;
case 2: mainTextController.text = [NSString stringWithFormat:@"%@ %@ ",username,@"AALBES"]; break;
case 3: mainTextController.text = [NSString stringWithFormat:@"%@ %@ ",username,@"AALDIJK"]; break;
default:
break;
}
但更好的是:
NSMutableArray* names = [[NSMutableArray alloc] init];
[names addObject:@"LEOONS"];
[names addObject:@"AAIING"];
[names addObject:@"AALBES"];
[names addObject:@"AALDIJK"];
NSString *username = [[GKLocalPlayer localPlayer] alias];
int text = arc4random_uniform([names count]); //again use arc4random_uniform
mainTextController.text = [NSString stringWithFormat:@"%@ %@ ",username,[names objectAtIndex:text]];