For those who have tried to use the Random() function in QSpice you may not have all the functionality you’d prefer.
Observations:
Here is a simple example of using the Random() as a input to a B-source. It is the file “rand_QSpice_test.qsch” in the attached archive of files.
Sim plot:
You’ll notice that the random value output of B1 doesn’t change across the entire sim time of 1 second.
You’ll also notice that each of the 10 steps executed have a different starting value. This is because I feed the step_val into the Random() as an input. This forces a different seed value.
However, this starting value is exactly the same at each step every time I run the entire sim. IMHO, I don’t think this is very random. I even used the seed and seedclock options. Still the same starting points. At least it is consistent across multiple sim runs. If that’s what you want.
Unless I’m missing something, this is what is provided natively in QSPice (or other Spice programs.)
Please reply with a correction if you have more information.
UPDATE: Here’s a link to @KSKelvin post who may have solved this issue. Monte Carlo analysis - #7 by lpoma
NEW COMPONENTS
I’ve created three new components using C-blocks (with symbols). You may find these components useful mostly in transient sims.
Here is the zip archive with an .txt extension. When you download it, remove the .txt extension.
rand.zip.txt (37.3 KB)
The new components are C-blocks that generate a bound-defined output. A new random number is generated on every timestep of the sim. It can be used to simulate noise or other needs for a linear distribution of random numbers across the defined bounds.
rand_i
The first component is “rand_i”. It is an signed integer-only output. You define the Lower Bounds (lb) and the Upper Bounds (ub) value. Parameter substitution can be used on the component such as stepping.
Here are the files in the archive that apply for this component:
- rand_i.cpp => C++ source code.
- rand_i_dll => compiled C++ .dll code.
- rand_i_qsym => symbol for the component. Useful for the “Symbol & IP Browser”
- rand_i_test.qsch => test sim for this component. This sim does lb and ub stepping.
Note: The component flags and abort the step/sim if the lb >= ub. It is illegal.
Here is an example plot of the first step with the out and LB and UB bounds.
rand_d
The component is “rand_d” operates like the “rand_i” but uses double (floating) output. This means it can output signed fractional values.
You define the Lower Bounds (lb) and the Upper Bounds (ub) value. Parameter substitution can be used on the component such as stepping.
Here are the files in the archive that apply for this component:
- rand_d.cpp => C++ source code.
- rand_d_dll => compiled C++ .dll code.
- rand_d_qsym => symbol for the component. Useful for the “Symbol & IP Browser”
- rand_d_test.qsch => test sim for this component. This sim does lb and ub stepping.
Note: The component flags and abort the step/sim if the lb >= ub. It is illegal.
Here is an example plot of the third step with the out and LB and UB bounds.
rand_dx
The component is “rand_dx” operates like the “rand_d” but uses two inputs for the lb and ub bounds.
The inputs allow for changing the bounds on-the-fly as the sim is running.
You define the Lower Bounds (lb) and the Upper Bounds (ub) value. Parameter substitution can be used on the component such as stepping.
Here are the files in the archive that apply for this component:
- rand_d.cpp => C++ source code.
- rand_d_dll => compiled C++ .dll code.
- rand_dx_qsym => symbol for the component. Useful for the “Symbol & IP Browser”
- rand_dx_test.qsch => test sim for this component. This sim uses B-sources to vary the bounds on-the-fly in the sim.
Note: The component flags and abort the step/sim if the lb >= ub. It is illegal.
Here is an example plot of out and the changing LB and UB bounds.
This components are free for anyone’s use. No warranty is expressed or implied.
Len