Skip to content

bryanluby/NSArray-Shuffle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NSArray-Shuffle

NSArray category for shuffling arrays.

Methods

bjl_shuffledArray

- (NSArray *)bjl_shuffledArray

Return Value

Returns an array where all elements are shuffled into random order.

bjl_shuffledArrayWithItemLimit:

- (NSArray *)bjl_shuffledArrayWithItemLimit:(NSUInteger)itemLimit

Parameters

itemLimit

The number of elements to randomly select from the array.

Return Value

Returns an array with a limited number of random elements.

Discussion

This method will improve performance if you only need a few elements out of a large dataset.

Usage

Add the NSArray+Shuffle.h and NSArray+Shuffle.m files to your Xcode project.

Information

This category implements the Fisher-Yates shuffle algorithm and uses the arc4random_uniform random number generator.

Helpful reference articles on array shuffling:

Fisher–Yates shuffle - Wikipedia, the free encyclopedia

Coding Horror: The Danger of Naïveté

Eli Bendersky's website » The intuition behind Fisher-Yates shuffling

License

MIT License

About

NSArray category for shuffling arrays.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published