Re: Seeding random() randomly
Re: Seeding random() randomly
- Subject: Re: Seeding random() randomly
- From: Jeffrey Walton <email@hidden>
- Date: Sat, 28 May 2011 16:55:53 -0400
On Thu, May 26, 2011 at 9:15 PM, Dave Keck <email@hidden> wrote:
>> I'm using random(), but every time I run my app I get the same sequence, despite having this code in my app delegate's -appDidFinishLaunching method. Clearly I'm not seeding it right, though I can't see why - I get a different value for seed every time. What gives?
>>
>>
>> unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 10000.0);
>>
>> NSLog(@"launched, seed = %ld", seed );
>> srandom( seed );
>
> I'm not sure what your problem is, but I believe arc4random() has
> superseded random() for a while now.
Be careful with ARC4 since its output is biased. The bias makes it
unsuitable for cryptographic/security related uses; and probably
unsuitable for other purposes, such as simulations, where a unifirm
distribution is usually needed.
Jeff
_______________________________________________
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