Mitul Dabhi
answered Nov 30 '-1 00:00
NSUInteger len =12;
NSString *letterd =@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#&@!?";
NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
for (NSUInteger i = 0; i < len; i++) {
u_int32_t r = arc4random() % [letterd length];
unichar c = [letterd characterAtIndex:r];
[randomString appendFormat:@"%C", c];
}
NSLog(randomString);
One can change len to change random string length
arc4random() is hero of this code which generate random number , The arc4random() function returns pseudo-random pseudorandom
random numbers in the range of 0 to (2**32)-1