summaryrefslogtreecommitdiff
path: root/Volta/Additions/NSMutableArray.m
diff options
context:
space:
mode:
Diffstat (limited to 'Volta/Additions/NSMutableArray.m')
-rw-r--r--Volta/Additions/NSMutableArray.m27
1 files changed, 27 insertions, 0 deletions
diff --git a/Volta/Additions/NSMutableArray.m b/Volta/Additions/NSMutableArray.m
new file mode 100644
index 0000000..0d7214b
--- /dev/null
+++ b/Volta/Additions/NSMutableArray.m
@@ -0,0 +1,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 \ No newline at end of file