I am using arc 4 random to choose a random entry from my fetchresultscontroller but I need to leave out all entries of a certain category. The column is "Category" and I dont want the random choice to include the category "Category2". Below is my current code, any help would be greatly appreciated!
- (NSIndexPath *)randomIndexPath
{
NSInteger randomSection = arc4random_uniform([[fetchedResultsController sections] count]);
id <NSFetchedResultsSectionInfo> sectionInfo =
[[fetchedResultsController sections] objectAtIndex:randomSection];
NSInteger randomIndex = arc4random_uniform( [sectionInfo numberOfObjects]);
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:randomIndex inSection:randomSection];
return indexPath;
}
- (IBAction)displayRandomEntry:(id)sender {
if([[fetchedResultsController sections] count] <= 0)
return;
NSIndexPath *indexPath = [self randomIndexPath];
[self.myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
id object = [fetchedResultsController objectAtIndexPath:indexPath];
RandomEntryDetailVC * controller;
controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowRandomEntryDetailVC"];
controller.currentItem = object;
[self.navigationController pushViewController:controller animated:YES];
}