blob: 0d7214b8f9fbd3270b8f3adcf52222631c4fdd59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
//
// NSMutableArray+Additions.m
// popquizshow
//
// Created by Ronny Fenrich on 2012-11-14.
// Copyright (c) 2012 Kyle Langille. All rights reserved.
//
#import "NSMutableArray+Additions.h"
@implementation NSMutableArray (Shuffling)
- (void)shuffle
{
NSUInteger count = [self count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
NSInteger nElements = count - i;
NSInteger n = (arc4random() % nElements) + i;
[self exchangeObjectAtIndex:i withObjectAtIndex:n];
}
}
@end
|