• 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: Seeding random() randomly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seeding random() randomly


  • Subject: Re: Seeding random() randomly
  • From: Graham Cox <email@hidden>
  • Date: Fri, 27 May 2011 11:32:34 +1000

On 27/05/2011, at 11:23 AM, Quincey Morris wrote:

> On May 26, 2011, at 18:00, Graham Cox wrote:
>
>> 	unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 10000.0);
>>
>> 	NSLog(@"launched, seed = %ld", seed );
>
> Also, be careful here, because %ld is the wrong format specifier for type 'unsigned'. Whether it logs the right value is going to be architecture dependent.

Ok, then that raises the question what should I use? I'm confused about how to correctly write format specifiers for both 32 and 64-bit runtimes. The 64-bit porting guide doesn't spell it out (yet you end up with code peppered with warnings that you should examine the use of the format specifier without docs properly explaining their correct use). It's also not clear to me whether just 'unsigned' is a fixed-size quantity or not, depending on architecture.

Someone mentioned that random() has been superseded. Again??! It seems to me that random number generators get superseded every other week. How is anyone supposed to know what is considered current best practice? Especially as for such functions there doesn't seem to be a simple way to see in man pages or other documentation what's deprecated.

--Graham_______________________________________________

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

  • Follow-Ups:
    • Re: Seeding random() randomly
      • From: Todd Heberlein <email@hidden>
    • Re: Seeding random() randomly
      • From: Roland King <email@hidden>
    • Re: Seeding random() randomly
      • From: Ken Thomases <email@hidden>
References: 
 >Seeding random() randomly (From: Graham Cox <email@hidden>)
 >Re: Seeding random() randomly (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Seeding random() randomly
  • Next by Date: Re: Seeding random() randomly
  • Previous by thread: Re: Seeding random() randomly
  • Next by thread: Re: Seeding random() randomly
  • Index(es):
    • Date
    • Thread