sympy: what's wrong with this picture?

Nanjundi nanjundi at gmail.com
Wed Mar 5 10:29:24 EST 2008


On Mar 4, 3:13 pm, Mensanator <mensana... at aol.com> wrote:
> On Mar 4, 12:32 pm, Nanjundi <nanju... at gmail.com> wrote:
>
>
> > Does seeding ( random.seed ) random with time fix this? It should.
>
> I suppose that depends on how long it takes factorint() to
> process a number. If the seed is reset before the next clock
> tick, you will get the same random numbers as the previous
> iteration.

Alright, then make it constant and don't worry about the clock tick.
>>> 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
...   random.seed(i)
...
5573 5171 [(5171, 1), (5573, 1)]
8537 7673 [(7673, 1), (8537, 1)]
2063 8573 [(2063, 1), (8573, 1)]
9551 9473 [(9473, 1), (9551, 1)]
2909 5659 [(2909, 1), (5659, 1)]
2897 1789 [(1789, 1), (2897, 1)]
6361 7541 [(6361, 1), (7541, 1)]
8017 8293 [(8017, 1), (8293, 1)]
3671 2207 [(2207, 1), (3671, 1)]
2803 9629 [(2803, 1), (9629, 1)]


> Frankly, I don't understand why factorint() reseeds at all.
Read the doc:
*    The rho algorithm is a Monte Carlo method whose outcome can be
affected by changing the random seed value.  *

> Doesn't Random automatically initialize the seed?
> Doesn't constantly reseeding degrade the performance of the
> random number generator? With Robert Kern's patch, the reseeding
> is no longer a constant, fixing the immediate symptom.

Does it matter? The factorint reseeds using a constant seed (1234).

>
> But what if _I_ wanted to make a repeatable sequence for test
> purposes? Wouldn't factorint() destroy my attempt by reseeding
> on every call?

Repeatable sequence? save it and reuse!
Think about "What if"s doesn't get any work done.

-N




More information about the Python-list mailing list