Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 27 lines (21 sloc) 0.595 kb
3629149 @tomcool420 added NSArray shuffling
authored
1 //
2 // NSArray_SMF.m
3 // SMFramework
4 //
5 // Created by Thomas Cool on 12/27/10.
6 // Copyright 2010 tomcool.org. All rights reserved.
7 //
8
9 #import "NSArray_SMF.h"
10
11
12 @implementation NSArray (SMFramework)
13 - (NSArray *) SMFShuffled
14 {
15 // create temporary autoreleased mutable array
16 NSMutableArray *tmpArray = [NSMutableArray arrayWithCapacity:[self count]];
17
18 for (id anObject in self)
19 {
20 NSUInteger randomPos = arc4random()%([tmpArray count]+1);
21 [tmpArray insertObject:anObject atIndex:randomPos];
22 }
23
24 return [NSArray arrayWithArray:tmpArray]; // non-mutable autoreleased copy
25 }
26 @end
Something went wrong with that request. Please try again.