[Tutor] random variable generation

Joshua Pollack jpollack@socrates.Berkeley.EDU
Thu May 29 18:21:37 2003


This is a multi-part message in MIME format.
--------------93ED7717CE21FDC28B1CEB78
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Some time ago I was working on a migration simulation and am picking it
up again, but I'm having some trouble with 
the use of RandomArray.binomial.

I've written a function to choose a random variable based on the length
of a list and an explicitly specified probability of success.

I run the function and then do the exact same thing outside of the
function call.

Problem is, I keep getting the exact same Random Variable from the
function call everytime I run it.


[jpollack@mws5 Arctic]$ python migrator.py
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2 10 0.1 <-- function calll
1 10 0.1 <-- non function call
[jpollack@mws5 Arctic]$ python migrator.py
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2 10 0.1 <-- function call
1 10 0.1 <-- nonfunction call
[jpollack@mws5 Arctic]$ python migrator.py
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2 10 0.1
2 10 0.1
[jpollack@mws5 Arctic]$ python migrator.py
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2 10 0.1
0 10 0.1
[jpollack@mws5 Arctic]$ python migrator.py
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2 10 0.1
0 10 0.1

etc...

I've attached the code.  I think the problem maybe with the seeding. 
I've looked at the RandomArray seed specifications and played around a
bit, but can't find anything that solves the problem.  I admit, I don't
understand the process of seeding all that well though.

If anyone has any ideas on how to fix this, let me know.  

Thanks,
Josh 

-- 
Joshua Pollack
Graduate Student, Slatkin
Lab                                             
4151 VLSB
Department of Integrative Biology
University of California-Berkeley 
jpollack@socrates.berkeley.edu
--------------93ED7717CE21FDC28B1CEB78
Content-Type: text/plain; charset=us-ascii;
 name="migrator.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="migrator.py"

import random,RandomArray

x=[[1]*10]
print x


migrationrate=.1

## define a function to generate a binomial random variable with parameters = list length and migration rate
def migration(list):

	nummigrants = RandomArray.binomial(len(list[0]) , migrationrate)
      	print nummigrants , len(list[0]) , migrationrate

migration(x)


## Do the same thing as my function, outside of a function call

nummig2 = RandomArray.binomial(len(x[0]) , migrationrate)
print nummig2 , len(x[0]) , migrationrate

--------------93ED7717CE21FDC28B1CEB78--