Re: Seeding a Random Number Generator

2003-12-07 Thread Tassilo von Parseval
On Sat, Dec 06, 2003 at 04:38:02PM -0800 John W. Krahn wrote:

 Pd Schloss wrote:

  I'm reviewing a perl script that someone wrote to do a statistical
  analysis.  I know it's bad form, but I was wondering if anyone knows
  what the default seed is for the random number generator in Perl.  They
  haven't seeded it with srand - what does this do?  It still seems to
  pick random numbers, any ideas?
 
 Download the source code for Perl if you don't already have it and have
 a look at the pp.c file.

The actual seed is calculated in Perl_seed() in util.c. The calculation
of the seed itself is highly dependent on the platform used. It involves
various things, such as gettimeofday(2), the PID, a value read from a
random device such as /dev/urandom, the position of PL_stack_sp in
memory etc. For most cases it should be quite ok.

Tassilo
-- 
$_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-07 Thread John W. Krahn
Tassilo Von Parseval wrote:
 
 On Sat, Dec 06, 2003 at 04:38:02PM -0800 John W. Krahn wrote:
 
  Download the source code for Perl if you don't already have it and have
  a look at the pp.c file.
 
 The actual seed is calculated in Perl_seed() in util.c. The calculation
 of the seed itself is highly dependent on the platform used. It involves
 various things, such as gettimeofday(2), the PID, a value read from a
 random device such as /dev/urandom, the position of PL_stack_sp in
 memory etc. For most cases it should be quite ok.

I did a grep -i -r 'seed' *.c and the only hit I got was in pp.c.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-07 Thread Owen
On Sun, 07 Dec 2003 03:29:02 -0800
John W. Krahn [EMAIL PROTECTED] wrote:


 I did a grep -i -r 'seed' *.c and the only hit I got was in pp.c.


FWIW

[EMAIL PROTECTED] perl-5.8.2]# grep -r seed
snip
util.c:Perl_seed(pTHX)
util.c:* is enough real entropy to fill the seed. */
util.c:Perl_get_hash_seed(pTHX)
util.c: UV myseed = 0;
util.c:   myseed = (UV)Atoul(s);
util.c:   /* Compute a random seed */
util.c:   (void)seedDrand01((Rand_seed_t)seed());
util.c:   myseed = (UV)(Drand01() * (NV)UV_MAX);
util.c:   myseed +=
util.c:   if (myseed == 0) { /* Superparanoia. */
util.c:   myseed = (UV)(Drand01() * (NV)UV_MAX); /* One more chance. */
util.c:   if (myseed == 0)
util.c: PL_rehash_seed_set = TRUE;
util.c: return myseed;
snip


 --
Owen



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-07 Thread John W. Krahn
Owen wrote:
 
 On Sun, 07 Dec 2003 03:29:02 -0800
 John W. Krahn [EMAIL PROTECTED] wrote:
 
  I did a grep -i -r 'seed' *.c and the only hit I got was in pp.c.
 
 FWIW
 
 [EMAIL PROTECTED] perl-5.8.2]# grep -r seed
 snip
 util.c:Perl_seed(pTHX)
 util.c:* is enough real entropy to fill the seed. */
 util.c:Perl_get_hash_seed(pTHX)
 util.c: UV myseed = 0;
 util.c:   myseed = (UV)Atoul(s);
 util.c:   /* Compute a random seed */
 util.c:   (void)seedDrand01((Rand_seed_t)seed());
 util.c:   myseed = (UV)(Drand01() * (NV)UV_MAX);
 util.c:   myseed +=
 util.c:   if (myseed == 0) { /* Superparanoia. */
 util.c:   myseed = (UV)(Drand01() * (NV)UV_MAX); /* One more chance. */
 util.c:   if (myseed == 0)
 util.c: PL_rehash_seed_set = TRUE;
 util.c: return myseed;

It must have been moved there for version 5.8 because it is not there in
5.6.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Seeding a Random Number Generator

2003-12-06 Thread PD Schloss
Hi,

I'm reviewing a perl script that someone wrote to do a statistical
analysis.  I know it's bad form, but I was wondering if anyone knows
what the default seed is for the random number generator in Perl.  They
haven't seeded it with srand - what does this do?  It still seems to
pick random numbers, any ideas?

Thanks,
Pat


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-06 Thread Rob Dixon
Pd Schloss wrote:

 I'm reviewing a perl script that someone wrote to do a statistical
 analysis.  I know it's bad form, but I was wondering if anyone knows
 what the default seed is for the random number generator in Perl.  They
 haven't seeded it with srand - what does this do?  It still seems to
 pick random numbers, any ideas?

Hi. I wrote this back in March. I assume I was right :)

Rob Dixon wrote:

 Interesting. Digging into the code for Perl v5.6.1, 'srand' will try to read four
 bytes from the /dev/urandom device. If that fails, then it will read the current
 time of day and mix it up with the PID, a Perl stack pointer and a few arbitrary
 constants.

So, as it should be, there is no 'default' seed.

This probably doesn't help, but at least should end your search!

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Seeding a Random Number Generator

2003-12-06 Thread John W. Krahn
Pd Schloss wrote:
 
 Hi,

Hello,

 I'm reviewing a perl script that someone wrote to do a statistical
 analysis.  I know it's bad form, but I was wondering if anyone knows
 what the default seed is for the random number generator in Perl.  They
 haven't seeded it with srand - what does this do?  It still seems to
 pick random numbers, any ideas?

Download the source code for Perl if you don't already have it and have
a look at the pp.c file.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response