Hi Guys,

According to my bookshelf, from 5.004 onwards srand uses a seed that's
"that's reasonably difficult to guess". Prior to that, it used time(). It
does seem as if the seed it being set the as the same value each time. Could
your program be being cached some where?

Otherwise a suggestion for a fairly random seed is as follows.

srand( time() ^ ($$ + ($$ << 15)) );

( time XOR (process_id + (process_id shift left 15)


Does rand give you identical subsequest values?


"Rob Dixon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Stefan Johnson wrote:
> > I know some people may complain and say I don't know what
> > I'm talking about, but I read somewhere recently (while
> > working on a dice function for my IRC bot) that "srand"
> > is no longer necessary.
>
> On the contrary, I'm sure you know what you're talking about
> Stefan, and you're quite right. The 'rand' function in Perl
> 5.004 was changed so that, on its first call, it would call 'srand'
> for you if you hadn't done so already.
>
> > You might try removing that line from your code and see
> > what errors you get (I doubt it will fix the problem, as it
> > quit working before on a system that it used to work on)
> > but it might generate an error.
>
> I doubt if removing it would make any difference, but it
> might be worth supplying it with a parameter. I don't know
> where 'srand' gets its default seed from, but it does look as
> though its always using the same one, which would then
> produce the same sequence of random numbers thereafter.
>
> Cheers,
>
> Rob
>
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to