Random in python 2.5 not working?

I think you need to give some more information. It's not really possible to answer why it's not working based on the information in the question. The basic documentation for random is at: https://docs.python.org/library/random.html

You might check there.


This is happening because you have a random.py file in the python search path, most likely the current directory.

Python is searching for modules using sys.path, which normally includes the current directory before the standard site-packages, which contains the expected random.py.

This is expected to be fixed in Python 3.0, so that you can't import modules from the current directory without using a special import syntax.

Just remove the random.py + random.pyc in the directory you're running python from and it'll work fine.


You probably have a file named random.py or random.pyc in your working directory. That's shadowing the built-in random module. You need to rename random.py to something like my_random.py and/or remove the random.pyc file.

To tell for sure what's going on, do this:

>>> import random
>>> print random.__file__

That will show you exactly which file is being imported.

Tags:

Python