Random Number Generator Error
ahmet nurlu
ahmet_nurlu at yahoo.com
Sat Mar 18 04:36:02 EST 2006
Hi,
I wrote a random walk program which you will find below. When I run it from the terminal, it gives error which I am not able to figure out what could be wrong. From the bash shell, I give a command
>python2.4 random.py
It gives error:
-----------------------------------------------------------------------------------------
Traceback (most recent call last):
File "random.py", line 2, in ?
from pylab import *
File "/usr/lib/python2.4/site-packages/pylab.py", line 1, in ?
from matplotlib.pylab import *
File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 196, in ?
import mlab #so I can override hist, psd, etc...
File "/usr/lib/python2.4/site-packages/matplotlib/mlab.py", line 58, in ?
import sys, random
File "/home/ofenerci/workspace/random.py", line 11, in ?
if (rand() > 0.5):
NameError: name 'rand' is not defined
[3] Done gedit random.py
-------------------------------------------------------------------------------------------------------------
When I write the program step by step inside the python2.4 shell or run it inside the python2.4-idle, everything goes smoothly and it doesn't give any error. I don't know why gives error, If I run it from the terminal.
thanks,
Ahmet Nurlu
Random.py Program:
---------------------------------------------------------------------------
from pylab import *
npts=1000
nplot=10
for i in range(0,nplot):
xplot=[]
x=0.0
for i in range(0,npts):
if (rand() > 0.5):
x=x+1
else:
x=x-1
xplot.append(x)
plot(xplot,'g')
hold(True)
show()
-------------------------------------------------------------------------
---------------------------------
Yahoo! Mail
Use Photomail to share photos without annoying attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060318/0abe7b9c/attachment.html>
More information about the Python-list
mailing list