Export to GitHub

sympy - issue #729

why does factorint break the random number generator?


Posted on Mar 3, 2008 by Massive Elephant

import sympy import time import random f = [i for i in sympy.primerange(1000,10000)] for i in xrange(10): f1 = random.choice(f) print f1, f2 = random.choice(f) print f2, C = f1*f2 ff = None ff = sympy.factorint(C) print ff

Note that the "random" choices are not random once factorint() is run.

7307 7243 [(7243, 1), (7307, 1)]

4091 6829 [(4091, 1), (6829, 1)]

8563 2677 [(2677, 1), (8563, 1)]

4091 6829 [(4091, 1), (6829, 1)]

8563 2677 [(2677, 1), (8563, 1)]

4091 6829 [(4091, 1), (6829, 1)]

8563 2677 [(2677, 1), (8563, 1)]

4091 6829 [(4091, 1), (6829, 1)]

8563 2677 [(2677, 1), (8563, 1)]

4091 6829 [(4091, 1), (6829, 1)]

run with factorint() commented out

6089 1811 None

6449 1759 None

9923 4639 None

4013 4889 None

4349 2029 None

6703 8677 None

1879 1867 None

5153 5279 None

2011 4937 None

7253 5507 None

Comment #1

Posted on Mar 3, 2008 by Quick Kangaroo

Thanks for the bugreport! Seems like the factorint is reseting the random seed...

Comment #2

Posted on Mar 3, 2008 by Happy Panda

Here's a patch.

Attachments

Comment #3

Posted on Mar 4, 2008 by Quick Kangaroo

Thanks Robert for the fix.

http://hg.sympy.org/sympy/rev/23ba03fd8dab

In [1]: import sympy

In [2]: import time

In [3]: import random

In [4]: f = [i for i in sympy.primerange(1000,10000)]

In [5]: for i in xrange(10): ...: f1 = random.choice(f) ...: print f1, ...: f2 = random.choice(f) ...: print f2, ...: C = f1*f2 ...: ff = None ...: ff = sympy.factorint(C) ...: print ff ...: 7237 2861 [(2861, 1), (7237, 1)] 5101 2377 [(2377, 1), (5101, 1)] 8563 2677 [(2677, 1), (8563, 1)] 4091 6829 [(4091, 1), (6829, 1)] 8563 2677 [(2677, 1), (8563, 1)] 4091 6829 [(4091, 1), (6829, 1)] 8563 2677 [(2677, 1), (8563, 1)] 4091 6829 [(4091, 1), (6829, 1)] 8563 2677 [(2677, 1), (8563, 1)] 4091 6829 [(4091, 1), (6829, 1)]

Comment #4

Posted on Mar 5, 2014 by Happy Elephant

We have moved issues to GitHub https://github.com/sympy/sympy/issues.

Comment #5

Posted on Apr 6, 2014 by Happy Rabbit

Migrated to http://github.com/sympy/sympy/issues/3828

Status: Fixed

Labels:
Type-Defect Priority-High Restrict-AddIssueComment-Commit