Select Page

capsules-shuffle-array

It’s very usual to randomize things, shuffle, mix… Our great app autoQuiniela has some smart/random algorithm, just because football is a probabilistic sport, not deterministic nor purely random.

Objective C provides a simple way to shuffle an NSMutableArray using categories. Categories are like extensions for already defined classes, so you can add new functions as “plugins“, that integrate perfectly with the base methods for the class.

Here’s the implementation for the Shuffling category.

NSMutableArray_Shuffling.h

NSMutableArray_Shuffling.m