objective c - Array from random objects of array -
this question has reply here:
picking random object in nsarray 7 answersi have array 20 elements.
myarray = @[ obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10, obj11, obj12, obj13, obj14, obj15, obj16, obj17, obj18, obj19, obj20];
i need randomly 10 of these elements , set them in array. how archieve this?
basically, utilize arc4random generate random number range of array.count, in loop iterates 10 times. within loop, fetch item @ indexrandomnumber, remove array , insert new array.
basic stuff. alternatively, sort or shuffle array (vcsjones) , grab first 10 items.
objective-c arrays sorting random
No comments:
Post a Comment