mardi 26 janvier 2016

Sympy reconfigures the randomness seed

The use of Python symbolic computation module "Sympy" in a simulation is impossible, I need to have reliable fixed inputs, for that I use the seed() in the random module. However every time I call a simple sympy function, it seems to overwrites the seed with a new value, thus getting new output every time. I have searched a little bit and found this. But neither of them has a solution.

Consider this code:

from sympy import * import random random.seed(1) for _ in range(2): x = symbols('x') equ = (x** random.randint(1,5)) ** Rational(random.randint(1,5)/2) print(equ)

This outputs

(x**2)**(5/2) x**4

on the first time, and

(x**2)**(5/2) (x**5)**(3/2)

On the second time, and every-time I run the script it returns new output. I need a way to fix this to enforce the use of seed().




Aucun commentaire:

Enregistrer un commentaire