Random Integer Generator
R2026bGenerate integers randomly distributed in specified range
Libraries:
Communications Toolbox /
Comm Sources /
Random Data Sources
Description
The Random Integer Generator block generates uniformly distributed random integers in the range [0, M-1], where M is specified by the Set size parameter. Use this block to generate random binary-valued or integer-valued data.
For information on achieving independent results for individual simulations run in parallel and on improving execution speed, see Tips.
Examples
Limitations
To use this block in a For Each Subsystem (Simulink) you must set Source of seed to
Autoand the model toNormalorAcceleratorsimulation mode. This ensures that each run will generate independent noise samples.
Ports
Output
Parameters
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
More About
Tips
Independent random numbers
To achieve independent and identically distributed (IID) streams when running simulations in parallel using the
parsim(Simulink) function, such as for Monte Carlo simulation runs, set Source of seed toParameterand make sure that all blocks have different Seed values.If workers use the same seed for this block, they can generate the same random stream of numbers, which can lead to misleading results. This can occur when you configure the model to run in rapid accelerator mode, and in this block set the Simulate using parameter to
Code generationand the Source of seed parameter toAuto.
For more information, see Choosing a Simulation Mode (Simulink).
Execution speed
To optimize execution speed:
When samples per frame (SPF) = 1 for long simulation runs (>>100k steps), set Simulate using to
Code generationand set Source of seed toAuto. This combination provides the fastest per-step execution.When SPF >> 1, set Simulate using to
Interpreted executionand set Source of seed toAuto. This combination provides the fastest total simulation time and there is no compiler dependency.




