0

We have NSSet for a collection of unordered unique elements and NSOrderedSet for a collection of ordered unique elements.

Still, we have NSArray for a collection of ordered non-unique elements, but no data structure for an unordered list of non-unique elements (as far as I know).

Does this container exist in Foundation? Is there a third-party container that manages such? If not either, is there a classy way of getting a randomized sequence of elements from an NSArray?

Matoe
  • 2,742
  • 6
  • 33
  • 52

1 Answers1

0

Easiest way is to use arc4random_uniform() which returns random numbers in the range:

example:

array[arc4random_uniform(array.count)];
Shams Ahmed
  • 4,498
  • 4
  • 21
  • 27