이 방법은 작동하지만 이론적으로는 종료되지 않을 수 있습니다. 관련없는 Es와 Ss를 다른 문자로 교체하여 강제 종료하는 것이 좋습니다.
사용자가 입력 한 길이가 2이면 확실히 반복됩니다.
BOOL canQuit = NO;
while (!canQuit)
{
NSMutableString *output = [[[NSMutableString alloc] init] autorelease];
while ([output length] < userDefinedLength)
{
//Generates a random character between a and z;
char c = ((arc4random() % (122 - 96)) + 97);
[output appendFormat:@"%c", c];
}
NSLog(@"%@", output);
int numberOfE = [output replaceOccurrencesOfString:@"e" withString:@"e" options:NSCaseInsensitiveSearch range:NSMakeRange(0, output.length)];
int numberOfS = [output replaceOccurrencesOfString:@"s" withString:@"s" options:NSCaseInsensitiveSearch range:NSMakeRange(0, output.length)];
canQuit = (numberOfE <= 1 && numberOfS >= 2 && numberOfS <= 4);
}