Skip to content

random module gives varying output for different Python versions #145

@tcld

Description

@tcld

As stated here #138 (comment) there seems to be a change in the random number generator between Python 2 and Python 3.

Starting from the same seed, the outputs between the two versions differ.

Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
[GCC 4.8.4] on linux
>>> import random
>>> random.seed(0)
>>> for x in range(0, 10):
...     random.randint(0, 1000000)
885440
403958
794772
933488
441001
42450
271493
536110
509532
424604
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.seed(0)
>>> for x in range(0, 10):
...     random.randint(0, 1000000)
844422
757955
420572
258917
511275
404934
783799
303313
476597
583382

This might be due to the different versions of gcc that have been used to compile the Python versions (I don't know how to test that right now) but since the maps here #138 (comment) are extremely similar I would expect that platec isn't influenced by the whole problem.

EDIT Here the pure code, if you want to quickly redo this:

import random
random.seed(0)
for x in range(0, 10):
    random.randint(0, 1000000)
import random
random.seed(0, version = 2)
for x in range(0, 10):
    random.randint(0, 1000000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions