# Monte Carlo analysis

Hello, I try to run the monte Carlo simulation, but I saw nowhere in the documentation related topics, so I tried to do it myself. For that I searched a random number generator function and the only clue I could find is on .option seed part. There on note 7 tells very little about the gauss() and random() functions. I tried to make it run with usual .step dummy 0 250 1, but I saw that the values of my voltage source, don’t change from simulation to simulation, and neither they are more than 9.
My question is. How can I increase the number of generated numbers? How I can tell to simulator to regenerate it on each simulation?
Thank you!

1 Like

Below would be the idea. This is one time curly braces would be recommended to enforce evaluation of random() by the preparser, and not by the random(x) function available during a simulation, the later being useful for generating things like a random bit stream.

I think the random() function should be rather indistinguishable from a true random sequence. It’s based on a Mersenne twister.

Mike,

I could be wrong about my interpretation of @Andru 's post.
I think he is asking for a “true random number generator”. The random() function works with a seed value. If I change the seed, I get a different starting point in the stepped sequence. (ie. .option SEED=4)

However, if the seed is the same between sim runs, it yields the same random() at each step between sims.

Is there a way to generate a “new” seed at the beginning of the sim?

For example in ‘C’ code, I have used the ‘low’ current time value (msec value) as the seed at the time of starting the application.

Len

@Engelhardt Ipoma interpretated Andru’s post as request of different seed at every run. In LTspice, there is an option to enable “Use the clock to reseed the MC generator” to generate different seed between run. Does Qspice has this feature?

In the meantime I found ways of generating with random() and with gauss() functions some kind of Monte Carlo points that I can plot it after with excel. But the problem persisted when rerunning the simulation, as the guys already explained. I just want to ask, is there a way/function that will generate new seed after a simulation restart, or it will be added a feature that we have to enable it in the future? Plus, in current state does save some calculating power/time by outsourcing the same points when the simulation is restarted? Thanks

OK, I just implemented

.options seedclock

It convolutes a 10MHz system clock with the simulation process ID to generate a physically random integer to seed the Mersenne Twister.

3 Likes

Mike,

I’ve tried using the .option seedclock with no luck.
See: Random values in simulations. New Components available!

However, using random(dummy) in the first post’s example yields a new starting value for each step but … it is the same starting value across sim runs for each step.

I’ve created 3 new components using C-blocks that might be of interest to the forum. Here’s the link:
See: Random values in simulations. New Components available!

Len

@lpoma Is this what you look for? Have to get use of Qspice variable “time” if you need a time dependent random.

Didn’t know that! I’ve got to check it out. Interesting. A random() of a random().

Question. At time = 0, is the value for V(random_time) always the same?
UPDATE: No it changes!!! Good to know.

Len

@lpoma I updated formula from `random(1e8*time*random())` to `random(1e8*(time+random()))`, as you are correct that previous formula at time = 0 always returns the same. I updated my post above for a better .tran random formula