# Resolving Random Number Generation Conflict with CasADi's \_set\_random\_seed

**URL:** <https://pybamm.discourse.group/t/resolving-random-number-generation-conflict-with-casadis-set-random-seed/283>\
**Category:** Solvers\
**Created:** [29 March 2025 02:19 UTC](https://pybamm.discourse.group/t/resolving-random-number-generation-conflict-with-casadis-set-random-seed/283 "2025-03-29T02:19:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![squirrel](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@squirrel](https://pybamm.discourse.group/u/squirrel)\
**Post date:** [29 March 2025 02:19 UTC](https://pybamm.discourse.group/t/resolving-random-number-generation-conflict-with-casadis-set-random-seed/283/1 "2025-03-29T02:19:28Z")

</div>

Hi,  
I encountered an issue when using the CasADi solver. While running the following code, I found that the random numbers were not being generated properly. I discovered that if the CasADi solver is used, the function `_set_random_seed` takes effect, causing the random numbers in my program to fail to generate correctly. How can I resolve this?

```
        action_norm = agent.select_action(state_norm)
        action_noise = (action_norm + np.random.normal(0, 1*expl_noise, size=1)).clip(-1, 1) # noise level 0.2
        action_applied = denormalize_input(action_noise, env.action_space.low[0], env.action_space.high[0])

```

next\_state, reward, is\_done, b = env.step(action\_applied)

in the “env.step”  
self.simulation = pybamm.Simulation(  
self.model,  
parameter\_values=self.param,  
experiment=experiment,  
solver=self.solver  
)  
the solver is casadi
