Skip to content

Instantly share code, notes, and snippets.

@akuraru
Created April 11, 2013 06:44
Show Gist options
  • Save akuraru/5361253 to your computer and use it in GitHub Desktop.
Save akuraru/5361253 to your computer and use it in GitHub Desktop.
[Objective-C]ランダムな長さのランダムな文字列を作る
- (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