I have the following method that should create a 20 character ID (sometimes with a prefix) and return the ID.
It seems to reset on launch and every time I use it it will create the same succession of identical numbers.
+(NSString *)createUniqueIdentifier:(NSString *)withPrefix {
NSString *outstring = nil;
if (withPrefix!=nil && ![withPrefix isEqualToString:@""]) {
outstring = [withPrefix stringByAppendingString:@"-"];
} else {
outstring = @"";
}
NSInteger ii;
NSString *allletters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (ii=0; ii<20; ii++) {
outstring = [outstring stringByAppendingString:[allletters substringWithRange:[allletters rangeOfComposedCharacterSequenceAtIndex:random()%[allletters length]]]];
}
return outstring;
}
I'm assuming this has something to do with random()
, but I don't know what else to use. I think I even got that suggestion from Stack Overflow.
Thanks for any help!