This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Random Integer Generator

Generate integers randomly distributed in specified range

  • Library:
  • Communications Toolbox / Comm Sources / Random Data Sources


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.

To ensure that the model uses different initial seeds, set the Simulate using parameter to Interpreted execution, and run the simulation in Normal or Accelerator mode. For more information, see Limitations.


For more information, see Choosing a Simulation Mode (Simulink).



expand all

Random integer output, returned as a scalar, vector, or matrix. This port is unnamed on the block. The data type is set using the Output data type parameter.

The number of rows in the output data equals the value of the Samples per frame parameter and corresponds to the number of samples in one frame. The number of columns in the output data equals the number of elements in the Set size parameter and corresponds to the number of channels.


expand all

Set size,M, specified as a positive integer or row vector of positive integers. The block generates integers in the range [0, (M – 1)]. The number of elements in Set size corresponds to the number of independent channels output from the block.

  • If Set size is a scalar, then all output random variables are independent and identically distributed (i.i.d.).

  • If Set size is a vector, then the length of the vector determines the number of output channels. The channels can have differing output ranges.

Source of the initial seed for the random number generator, specified as either:

  • Auto –– the block uses the global random number stream

  • Parameter –– the block sets the random number generator seed to Initial seed

Initial seed value for the random number generator, specified as a nonnegative integer. If the Initial seed parameter is a constant, then the resulting sequence is repeatable.


To enable this parameter, set the Source of initial seed parameter to Parameter.

Sample time in seconds, specified as a positive scalar indicating the time between each sample in a column of the output data.

Samples per frame, specified as a positive integer indicating the number of samples per frame in one channel of the output data.


The time between output updates is equal to the product of Samples per frame and Sample time. For example, if Sample time and Samples per frame equal 1, the block outputs 1 integer every 1 second. If Samples per frame is increased to 10, then a 10-by-1 vector of integers is output every 10 seconds. The equivalent output rate is not dependent on the Samples per frame parameter.

Output data type, specified as double, single, uint8, uint16, uint32, or boolean. If this parameter is set to boolean, you must set the Set size parameter to 2.

Type of simulation to run, specified as:

  • Code generation –– Simulate the model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time.

  • Interpreted execution –– Simulate the model using the MATLAB® interpreter. This option shortens startup time. In Interpreted execution mode, you can debug the source code of the block.

Block Characteristics

Data Types

double | single | Boolean | base integer

Multidimensional Signals


Variable-Size Signals


Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

See Also


Introduced before R2006a