On Wed, Jul 11, 2001 at 12:34:37AM -0400, Walt Mankowski wrote:
> On Tue, Jul 10, 2001 at 07:27:04PM -0700, Erik W wrote:
> > $$<<15 ???
> 
> This shifts the value of $$ 15 bits to the left, which is the same as
> multiplying $$ by 2**15.

I forgot to reference the code you were referring to:

>> time() ^ ($$ + ($$ << 15))

The reason they're shifting $$ 15 bits to the left is that they're
assuming that the process id (which is what $$ is) is a 15-bit
integer.  This has been traditionally true in Unix, but I believe I've
read about some support in recent Linux kernels for >32767 processes.

Once they leftshift it 15 bytes, the rightmost 15 bytes are 0.  By
adding $$ to it they fill in those empty bytes with $$ again.  The
result is a 30-bit number consisting of the bits in $$ repeated twice.

There are better methods of seeding random number generators, so this
method is mainly of educational and historical interest.  As Jeff
mentioned, in modern perls rand() will call srand() automatically the
first time it's called.

Walt

Reply via email to