Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. NSMutableArray *selectionPool = ...;
  2.  
  3. int numberOfObjectsToSelect = x;
  4.  
  5. NSMutableArray *selectedObjects = [[NSMutableArray alloc] initWithCapacity:numberOfObjectsToSelect];
  6.  
  7. int modulus = selectionPool.count - 1;
  8.  
  9. for (int i = 0; i < numberOfObjectsToSelect; i++) {
  10.  
  11. int j = arc4random() % (modulus--);
  12. [selectedObjects addObject:[selectionPool objectAtIndex:j]];
  13. [selectionPool removeObjectAtIndex:j];
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement