Hi, what time() ^ $$ means?

2001-07-10 Thread Erik W

Hi gurus,

I have a dumb question, 
when I read the book, I saw they generate and seed by 
using 

time() ^ $$

What ^ and $$ mean here?

^   bit xor?
$$  logic and?

Thanks in advance!


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Jeff 'japhy' Pinyan

On Jul 10, Erik W said:

>when I read the book, I saw they generate and seed by 
>using 

Just so you know, you don't need to call srand() in modern versions of
Perl.

>^   bit xor?

Yes.

>$$  logic and?

Nope, that'd be &&.  $$ is the process ID (or PID) variable.  Check
'perlvar'.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Stephen P. Potter

Lightning flashed, thunder crashed and Erik W <[EMAIL PROTECTED]> whispered:
| time() ^ $$
| 
| What ^ and $$ mean here?
| 
| ^   bit xor?
| $$  logic and?

$$ is a special variable that is the process ID of the currently running
process.  So, this is returning the bitwise xor of the return of time
(seconds since epoch) and the process ID (generally something between 2 and
65536).  Since perl 5.004 or so, this has been mostly unnecessary.  Even if
it was still necessary, it would probably be better to use something like

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

which at least gives two numbers of roughly the same magnitude.

-spp
--
Stephen P Potter[EMAIL PROTECTED]
"You can't just magically invoke Larry and expect that to prove your point.
Or prove that you have a point."-Simon Cozens
http://www.unixlabs.net/~spp/




Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Erik W


--- "Stephen P. Potter" <[EMAIL PROTECTED]>
wrote:
> Lightning flashed, thunder crashed and Erik W
> <[EMAIL PROTECTED]> whispered:
> | time() ^ $$
> | 
> | What ^ and $$ mean here?
> | 
> | ^   bit xor?
> | $$  logic and?
> 
> $$ is a special variable that is the process ID of
> the currently running
> process.  So, this is returning the bitwise xor of
> the return of time
> (seconds since epoch) and the process ID (generally
> something between 2 and
> 65536).  Since perl 5.004 or so, this has been
> mostly unnecessary.  Even if
> it was still necessary, it would probably be better
> to use something like
> 
> time() ^ ($$ + ($$ << 15))
Thanks a lot, then what << means?
$$<<15 ???

perl is really unreadable!

> 
> which at least gives two numbers of roughly the same
> magnitude.
> 
> -spp
> --
> Stephen P Potter  [EMAIL PROTECTED]
> "You can't just magically invoke Larry and expect
> that to prove your point.
> Or prove that you have a point."  -Simon Cozens
> http://www.unixlabs.net/~spp/
> 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: Hi, what time() ^ $$ means?

2001-07-10 Thread matthschulz

Am Dienstag, 10. Juli 2001 21:27 schrieb Erik W:
> --- "Stephen P. Potter" <[EMAIL PROTECTED]>
>
> wrote:
> > Lightning flashed, thunder crashed and Erik W
> >
> > <[EMAIL PROTECTED]> whispered:
> > | time() ^ $$
> > |
> > | What ^ and $$ mean here?
> > |
> > | ^   bit xor?
> > | $$  logic and?
> >
> > $$ is a special variable that is the process ID of
> > the currently running
> > process.  So, this is returning the bitwise xor of
> > the return of time
> > (seconds since epoch) and the process ID (generally
> > something between 2 and
> > 65536).  Since perl 5.004 or so, this has been
> > mostly unnecessary.  Even if
> > it was still necessary, it would probably be better
> > to use something like
> >
> > time() ^ ($$ + ($$ << 15))
>
> Thanks a lot, then what << means?
> $$<<15 ???
>
from perlbook.pdf: (pg.166)

Shift Operators
Binary "<<" returns the value of its left argument shifted left by the number 
of bits specified by the right
argument. Arguments should be integers. (See also Integer Arithmetic.)


> perl is really unreadable!
>
> > which at least gives two numbers of roughly the same
> > magnitude.
> >
> > -spp
> > --
> > Stephen P Potter[EMAIL PROTECTED]
> > "You can't just magically invoke Larry and expect
> > that to prove your point.
> > Or prove that you have a point."-Simon Cozens
> > http://www.unixlabs.net/~spp/
>
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/



Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

On Tue, Jul 10, 2001 at 09:56:55PM -0400, Jeff 'japhy' Pinyan wrote:
> Just so you know, you don't need to call srand() in modern versions of
> Perl.

Unless, of course, you want to seed the random number generator to a
specific value.  :-)

Walt




Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

On Tue, Jul 10, 2001 at 07:27:04PM -0700, Erik W wrote:
> Thanks a lot, then what << means?

>From perldoc perlop...

   Binary "<<" returns the value of its left argument shifted left
   by the number of bits specified by the right argument.
   Arguments should be integers.  (See also the Integer Arithmetic
   entry elsewhere in this document.)

A left shift of n bits is the same as multiplying by 2 n times, and a
right shift is the same as dividing by 2 n times.  Sometimes it's
easier to think of the bits as moving to the left or right than to
think of multiplying or dividing by powers of 2, but they're really
the same operation.

> $$<<15 ???

This shifts the value of $$ 15 bits to the left, which is the same as
multiplying $$ by 2**15.

> perl is really unreadable!

Actually bit manipulation is pretty basic computer science.  Perl
borrowed the operators from C.

Walt



Re: Hi, what time() ^ $$ means?

2001-07-10 Thread Walt Mankowski

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



RE: Hi, what time() ^ $$ means?

2001-07-11 Thread Gary L. Armstrong

Trivially speaking, AIX goes past 32k PID numbers as well.  I believe that
v4r3 allows 32k open files per process as well. If anyone would care for
detail (and why would you???) email me at [EMAIL PROTECTED] instead of
the list so that I can look it up, and I can try to stay in topic. =)

G. Armstrong

Lost .sig in format

-Original Message-
From: Walt Mankowski [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 11, 2001 12:50 AM
To: [EMAIL PROTECTED]
Subject: Re: Hi, what time() ^ $$ means?


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




Re: Hi, what time() ^ $$ means?

2001-07-11 Thread Stephen P. Potter

Lightning flashed, thunder crashed and Erik W <[EMAIL PROTECTED]> whispered:
| Thanks a lot, then what << means?
| $$<<15 ???

It seems to me that you need to spend some time with a good beginners book,
such as Randal's.  Or, at least, the man pages.  These questions are easily
answered with a quick hunt through perlfunc (for the rand/srand question),
perlvar (for $$), and perlop (for <<).

<< is the left bit shift operator.  It returns the first operand with the
bits shifted the right operand number of times.

-spp




Re: Hi, what time() ^ $$ means?

2001-07-12 Thread EriK W

Excellent!

Thank you all for your help!

I am going to spend more time on man pages or beginners book.

What is the best beginners book in you opinion?

Thank you very much!



On Wed, 11 Jul 2001 12:07:47 -0400
"Stephen P. Potter" <[EMAIL PROTECTED]> wrote:

> Lightning flashed, thunder crashed and Erik W <[EMAIL PROTECTED]> whispered:
> | Thanks a lot, then what << means?
> | $$<<15 ???
> 
> It seems to me that you need to spend some time with a good beginners book,
> such as Randal's.  Or, at least, the man pages.  These questions are easily
> answered with a quick hunt through perlfunc (for the rand/srand question),
> perlvar (for $$), and perlop (for <<).
> 
> << is the left bit shift operator.  It returns the first operand with the
> bits shifted the right operand number of times.
> 
> -spp



_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




Re: Hi, what time() ^ $$ means?

2001-07-12 Thread Stephen P. Potter

Lightning flashed, thunder crashed and EriK W <[EMAIL PROTECTED]> whispered:
| Excellent!
| 
| Thank you all for your help!
| 
| I am going to spend more time on man pages or beginners book.
| 
| What is the best beginners book in you opinion?

Currently, I like "A Little Book on Perl" by Robert Sebesta (ISBN
0139279555).  It's nice and small and easy to get into.

I'm waiting to see a copy of "Learning Perl, 3rd edition" (Randal, HINT!).
I was disappointed with the second edition (I'll keep to myself how I think
it happened), but hold great hope for the third edition.

-spp
--
Stephen P Potter [EMAIL PROTECTED]
"You can't just magically invoke Larry and expect that to prove your point.
Or prove that you have a point."-Simon Cozens
UNIX and Perl Consulting and Training http://www.unixlabs.net/~spp/