Skip to content

Instantly share code, notes, and snippets.

@rbaulin
Created March 29, 2015 10:50
Show Gist options
  • Save rbaulin/0decc2b3df09ae49a8d5 to your computer and use it in GitHub Desktop.
Save rbaulin/0decc2b3df09ae49a8d5 to your computer and use it in GitHub Desktop.
- (NSString *)randomString {
NSString *alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789";
u_int32_t len = arc4random_uniform(20) + 5;
NSMutableString *s = [NSMutableString stringWithCapacity:len];
for (NSUInteger i = 0U; i < len; i++) {
u_int32_t r = arc4random() % [alphabet length];
unichar c = [alphabet characterAtIndex:r];
[s appendFormat:@"%C", c];
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment