Different Random Numbers Between Already/Not Yet Compiled Code

Tim Peters tim.one at home.com
Mon Jan 21 21:51:56 EST 2002


[Eric Eide]
> D'oh! --- I forgot to give my particulars.  I'm using:
>
> 	Python 2.0 (#2, Apr 18 2001, 21:17:05)
> 	[GCC 2.95.3 [FreeBSD] 20010315 (release)] on freebsd4

That's not so interesting as the exact code you use to set the seed, whether
you're using threads, and whether you're using any standard or extension
modules that also use the default random instance.

It may have to do with that, back in 2.0, the values of manifest
floating-point constants could change between .py and .pyc formats, due to
ill-considered rounding in the .pyc format.

For example, here's module floater.py:

X = 1.234567801234567
print repr(X)

And here's a 2.0.1 session:

C:\Python20>python
Python 2.0.1 (#18, Jun 22 2001, 02:26:03) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import floater   # imported from .py
1.2345678012345671
>>> reload(floater)  # reloaded from .pyc -- oops!  lost precision
1.2345678012300001
<module 'floater' from 'floater.pyc'>
>>>

Don't know about 2.1; it's definitely fixed in 2.2:

C:\Python22>python
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import floater
1.2345678012345671
>>> reload(floater) # same thing from .pyc
1.2345678012345671
<module 'floater' from 'floater.pyc'>
>>>





More information about the Python-list mailing list