Seeding random() randomly
Seeding random() randomly
- Subject: Seeding random() randomly
- From: Graham Cox <email@hidden>
- Date: Fri, 27 May 2011 11:00:47 +1000
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 );
--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