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 (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to