Skip to content

Instantly share code, notes, and snippets.

@brankoajzele
Last active December 16, 2015 09:28
Show Gist options
  • Save brankoajzele/5412688 to your computer and use it in GitHub Desktop.
Save brankoajzele/5412688 to your computer and use it in GitHub Desktop.
Loto number generator
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
/* Loto _x out of _y */
int _x = 7, _y = 39;
NSMutableArray *numbers = [[NSMutableArray alloc] init];
while ([numbers count] < _x) {
int x = arc4random_uniform(_y + 1);
if (x == 0) { continue; }
NSNumber *number = [NSNumber numberWithInteger:x];
if ([numbers containsObject:number] == NO) {
[numbers addObject:number];
}
}
NSArray *lotoNumbers = [numbers sortedArrayUsingSelector: @selector(compare:)];
NSLog(@"Numbers %@", lotoNumbers);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment