0

Using int rand=((arc4random()%4)+1); how would you make a sorted list based on the numbers generated which have to be clicked in order .Example if 4 2,3,1 was generated you have to click images based on those numbers ?

alec
  • 3
  • 4
  • 2
    This question has *nothing* inherently to do with random. Assume that there is a list [x,y,z] (where z, y and z are arbitrary integers) - how would you sort it? However, consider that a [*shuffle*](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle) might be more appropriate if the values don't need to be random, but the order does. – user2246674 Jun 18 '13 at 03:17
  • See [this answer](http://stackoverflow.com/a/56656/335858), it does what you are looking for. The question is different, so it's not a duplicate. – Sergey Kalinichenko Jun 18 '13 at 03:27

1 Answers1

0

You could keep those integers [x,y,z] in a mutable array. and if you want the user to click x then y then z (indexing ascending order) then you could check the object at index 0 and see if it matches your image (I'm assuming you can map an integer to your image somehow). If it does, remove the object at index 0 from the list, if it doesn't, tell the user they have failed.

When the list is empty you know they have succeeded. you should check this after ever time your remove index 0.

atreat
  • 4,243
  • 1
  • 30
  • 34
  • I don't see why or where you would need a sorted list – atreat Jun 18 '13 at 03:28
  • if you have objects 4,1,2,3 appear you have to click objects 4,1,2,3 in order or you loose – alec Jun 18 '13 at 03:40
  • yep. thats what I describe above. but that doesn't involve sorting a list. A list [4,1,2,3] would be sorted as [1,2,3,4] which I feel is unnecessary for you. – atreat Jun 18 '13 at 03:48