Re: Seeding random() randomly
Re: Seeding random() randomly
- Subject: Re: Seeding random() randomly
- From: Roland King <email@hidden>
- Date: Fri, 27 May 2011 09:55:24 +0800
I don't think random/srandom are superseded. I use them myself for game creation. The game just has one number associated with it, I use that to seed random and I can completely recreate the whole game from that one number.
I use the slightly more complicated initstate version. I see no reason why your method isn't working however.
Two things to try. Print the first few randoms right after you seed to prove to yourself that you are seeding. Put a breakpoint on srandom, initstate and setstate to see if another piece of code is stomping yours.
On May 27, 2011, at 9:32, Graham Cox <email@hidden> wrote:
>
> 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
_______________________________________________
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