Last active
December 11, 2015 14:09
-
-
Save jonathanpenn/4612637 to your computer and use it in GitHub Desktop.
Here's how I'm generating a set of 1,000 random strings with between 4 and 14 random lowercase characters. Is there a better way?
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
@implementation SomeGenerater | |
- (NSArray *)generateAThousandRandomStrings | |
{ | |
NSMutableArray *strings = [[NSMutableArray alloc] initWithCapacity:1000]; | |
for (int count = 0; count < 1000; count++) { | |
int length = arc4random_uniform(10) + 4; | |
unichar buf[length]; | |
for (int idx = 0; idx < length; idx++) { | |
buf[idx] = (unichar)('a' + arc4random_uniform(26)); | |
} | |
[strings addObject:[NSString stringWithCharacters:buf length:length]]; | |
} | |
return strings; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eraserhd you have proven yourself with this one. :)