Generating a random number

Magnus Lie Hetland mlh at idi.ntnu.no
Sat Oct 6 19:47:39 CEST 2001


"Ron White" <rwhite at netins.net> wrote in message
news:9pnb95$aug$1 at ins22.netins.net...
> Hi,
> When I used the following I got:
>
> >>> from random import randrange
> Traceback (most recent call last):
>   File "<pyshell#0>", line 1, in ?
>     from random import randrange
>   File "C:\PYTHON21\Tools\idle\random.py", line 3
>     for i in range(10):
>     ^
> SyntaxError: invalid syntax
> >>>

Hm. This doesn't seem like the random module. It should be located
at C:\PYTHON21\Lib\random.py

Also, it does not contain the line "for i in range(10):", as far as
I can see. Are you sure this isn't a script that you've written
yourself that's being imported by mistake (because you've put
it in your PYTHONPATH)? As far as I can see, the standard distribution
does not include a file called random.py in the idle directory...

> The one thing that has worked is from Dale Strickland-Clark.  That is:
>
> from whrandom import randint
>
> print randint(1, 10)

Yes, this works, but it is deprecated. If you try to move the
random.py file away from its current location (where it probably
shouldn't be) you will probably be able to get the _real_
random library, and this should work:

  from random import randrange

  print randrange(10)+1

> I wonder if my random module is corrupt?

The one you are importing is, it seems... But probably not
the real library :)

> Ron

--

  Magnus Lie Hetland         http://www.hetland.org

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick






More information about the Python-list mailing list