Skip to content

Instantly share code, notes, and snippets.

@mchow01
Created October 10, 2013 01:21
Show Gist options
  • Save mchow01/6911526 to your computer and use it in GitHub Desktop.
Save mchow01/6911526 to your computer and use it in GitHub Desktop.
Generate 100 cryptographically secure random integers between 0 - 99 inclusive in Objective-C.
FILE *fp = fopen("/dev/random", "r");
if (!fp) {
/*UIAlertView *error = [[UIAlertView alloc]initWithTitle:@"Failure"
message:@"Sorry, cryptographically secure random numbers could not be generated."
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[error show];*/
}
int count;
for (count = 0 ; count < 100; count++) {
NSLog(@"%d", (int)fgetc(fp) % 100);
}
fclose(fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment