You are here

Setting the seed for pseudo random number from R

Hello, 

We are running a Simile model via R. In the model, we use rand_var and rand_const functions and we would need to set the seed for debugging purposes. 

We see that this is possible to set the seed in the Model>Run section using the Add>Initialize pseudo-random. However, we are launching the model using the R package Simile. I searched the documentation, but I cannot find a way to set the seed.

Is there a way to do it? Is there an R command for this? or is there a way to add the seed in the spf files?

Thanks for your help!

Best regards,

Claudio

Forums: 

This can be done by passing a command directly to the Tcl interpreter. Use this form:

tcl("SeedRandoms", e1, 94)

where e1 is the handle to the executing instance and 94 is an integer that will form the new seed.

Hope this helps!

Hi again, we are running multiple times the same model, within a loop. Inside the loop, we do: ```R for (i in 1:No_simulations) { flog.info(paste0("Simulation number: ", i)) tic("\nTotal elapsed time for one simulation") # i <- 1 initialize the model, including default slider values reset.model(iHandle, -2) ... ``` When is the right moment to seed the seed, before or after the "reset.model" ? BR

for (i in 1:No_simulations) {
flog.info(paste0("Simulation number: ", i))
tic("\nTotal elapsed time for one simulation")
# i <- 1 initialize the model, including default slider values
reset.model(iHandle, -2)

You should set the seed just before resetting the model, since the first set of random values will be calculated on the reset step.