Re: -[NSMutableSet randomObject]
Re: -[NSMutableSet randomObject]
- Subject: Re: -[NSMutableSet randomObject]
- From: Dave DeLong <email@hidden>
- Date: Tue, 25 May 2010 10:54:47 -0600
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden