• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: -[NSMutableSet randomObject]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSMutableSet randomObject]


  • Subject: Re: -[NSMutableSet randomObject]
  • From: Thomas Davie <email@hidden>
  • Date: Tue, 25 May 2010 19:24:21 +0100

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@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

_______________________________________________

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

References: 
 >-[NSMutableSet randomObject] (From: "Michael A. Crawford" <email@hidden>)
 >Re: -[NSMutableSet randomObject] (From: Dave DeLong <email@hidden>)
 >Re: -[NSMutableSet randomObject] (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: Custom View Binding, Arrays, and observeValueForKeyPath (solved)
  • Next by Date: Crash trying to unarchive webview from IB document
  • Previous by thread: Re: -[NSMutableSet randomObject]
  • Next by thread: Re: -[NSMutableSet randomObject]
  • Index(es):
    • Date
    • Thread