Created
April 11, 2013 06:44
-
-
Save akuraru/5361253 to your computer and use it in GitHub Desktop.
[Objective-C]ランダムな長さのランダムな文字列を作る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)randStringWithMaxLenght:(NSInteger)max { | |
NSInteger length = [self randBetween:1 max:max]; | |
unichar letter[length]; | |
for (int i = 0; i < length; i++) { | |
letter[i] = [self randBetween:65 max:90]; | |
} | |
return [[NSString alloc] initWithCharacters:letter length:length]; | |
} | |
- (NSInteger)randBetween:(NSInteger)min max:(NSInteger)max { | |
return (random() % (max - min + 1)) + min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment