If I create a new NSData object of a specific size using dataWithBytes:length:, what is the most efficient way to create the input bytes (20 Mb worth) of random characters, pref
Use arc4random_buf
to fill the buffer with random bytes
Obj-C
+ (nullable NSData *)radomDataOfSize:(size_t)sizeInBytes
{
void *buff = malloc(sizeInBytes);
if (buff == NULL) {
return nil;
}
arc4random_buf(buff, sizeInBytes);
return [NSData dataWithBytesNoCopy:buff length:sizeInBytes freeWhenDone:YES];
}