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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -