python - Sympy reconfigures the randomness seed -
the use of python symbolic computation module "sympy" in simulation difficult, need have reliable fixed inputs, use seed() in random module. every time call simple sympy function, seems overwrites seed new value, getting new output every time. have searched little bit , found this. neither of them has solution.
consider code:
from sympy import * import random random.seed(1) _ 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 first run, ,
(x**2)**(5/2) (x**5)**(3/2)
on second run, , every-time run script returns new output. need way fix enforce use of seed().
does help? docs on random:
"you can instantiate own instances of random generators don’t share state"
usage:
import random # create new pseudo random number generator prng = random.random() prng.seed(1)
this number generator unaffected sympy
Comments
Post a Comment