If this is indeed the desired effect, you're much better off writing a -
(NSArray *)arrayByRandomlyOrderingObjects in an NSArray category, and then
calling [[mySet allObjects] arrayByRandomlyOrderingObjects];.
Bob
On 25 May 2010, at 17:54, Dave DeLong wrote:
> Ah, I see; you don't want to provide the same object twice in a row. If
> that's the case, is it really "random"? ;)
>
> Dave
>
> On May 25, 2010, at 10:52 AM, Dave DeLong wrote:
>
>> What about something like:
>>
>> @implementation NSSet (Random)
>>
>> - (id) randomObject {
>> NSArray * allObjects = [self allObjects];
>> if ([allObjects count] == 0) { @throw ...; }
>> return [allObjects objectAtIndex:(arc4random() % [allObjects count])];
>> }
>>
>> @end
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/tom.davie%40gmail.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]