[ python-Bugs-1023453 ] script which sets random.seed still returns random value

SourceForge.net noreply at sourceforge.net
Wed Sep 8 00:19:29 CEST 2004


Bugs item #1023453, was opened at 2004-09-07 05:40
Message generated for change (Comment added) made by fmitha
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1023453&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Faheem Mitha (fmitha)
Assigned to: Nobody/Anonymous (nobody)
Summary: script which sets random.seed still returns random value

Initial Comment:
Hi,

The following text is in the README in the attached
tarball. Note also that I'd be happy to try to narrow
down the bug further, if indeed there is one. I just
wanted to confirm first that there indeed was a bug.

This is with python 2.3 and numarray 1.0 on Debian sarge.
ii  python-numarray            1.0-2                  
   An array processing package modelled after
Python-Numeric
ii  python                     2.3.4-1                
   An interactive high-level object-oriented language
(default version)

(By the way, I'd really, really prefer to submit
reports via email, like the Debian bug tracking
system). It is also not very convenient to follow up to
replies.
                                                      
                      Faheem

*************************************************************
Run the included script (requires python 2.3)

python bug.py

Even though the seed is set before gendata is called,
every time the script is run, a different matrix is
printed. It seems to me that this should not happen. My
interest in this case is ensuring
reproducibility for debugging purposes.

I am not an expert on random numbers, so I may be
missing some subtle point. If so, I'm appreciate it if
my error was explained to me.

Thanks.                                               
Faheem Mitha.


----------------------------------------------------------------------

>Comment By: Faheem Mitha (fmitha)
Date: 2004-09-07 22:19

Message:
Logged In: YES 
user_id=1063525


> Date: 2004-09-07 08:47
> Sender: rhettinger
> Logged In: YES 
> user_id=80475

> There are two independent random number generators in your
code.  

> One is in the random module and you're accessing it with
> random.seed() and random.gammavariate().  The seed operation
> will correctly make gammavariate() create a reproducable
> sequence.

> The second is in numarray.random_array.multinomial.  This
> generator is provided by numarray and needs its own seed
> operation.  Seed it, and your program ought to work fine. 
> See the numarray docs for details on how to seed random_array.

I see. Thanks for explaining this. I did try to track down
this bug, but I never realised that numarray was using a
different random number generator. I think it would be a
good idea to standardise on a single interface.

> For the future, please do not attach tar.gz files.  They are
> a nuisance to review.  

What do you want instead?

1) Code attached as text file?
2) Code included in the message? I don't think this would
work as the web form would probably mess up the indentation.
3) A link to a web page? But this would mean the info would
not be contained in the bug report for posterity. :-)

Or something else?

> More importantly, you should pair down the report to the
simplest 
> possible code that reproduces the error.  Otherwise, a
reviewer has to 
> read all of your code to figure out what you're doing.

Yes, I probably should have taken the time to narrow down
the problem, and in the process might have solved it. 

However, at the time I submitted, I had already run into
this problem several times without figuring it out, and had
spent some time narrowing down the problem to a region of
code. As I said in the report, I just 
wanted to confirm that this actually was a bug. As I also
said, I was quite  willing to spend additional time
narrowing it down if it was indeed a bug, but in in the
first place it seemed difficult since I had no idea why it
should occur. 

                                                           
                         Faheem.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-07 08:47

Message:
Logged In: YES 
user_id=80475

There are two independent random number generators in your
code.  

One is in the random module and you're accessing it with
random.seed() and random.gammavariate().  The seed operation
will correctly make gammavariate() create a reproducable
sequence.

The second is in numarray.random_array.multinomial.  This
generator is provided by numarray and needs its own seed
operation.  Seed it, and your program ought to work fine. 
See the numarray docs for details on how to seed random_array.

For the future, please do not attach tar.gz files.  They are
a nuisance to review.  More importantly, you should pair
down the report to the simplest possible code that
reproduces the error.  Otherwise, a reviewer has to read all
of your code to figure out what you're doing.

Good luck and happy computing.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1023453&group_id=5470


More information about the Python-bugs-list mailing list