Random Number
Generate normally distributed random numbers
Library
Sources
![](http://www.tatmou.com/help/releases/R2017b/simulink/slref/random_number_block_icon.png)
Description
The Random Number block generates normally distributed random numbers. To generate uniformly distributed random numbers, use theUniform Random Numberblock.
You can generate a repeatable sequence using any Random Number block with the same nonnegative seed and parameters. The seed resets to the specified value each time a simulation starts. By default, the block produces a sequence that has a mean of 0 and a variance of 1. To generate a vector of random numbers with the same mean and variance, specify theSeedparameter as a vector.
Avoid integrating a random signal, because solvers must integrate relatively smooth signals. Instead, use theBand-Limited White Noiseblock.
The numeric parameters of this block must have the same dimensions after scalar expansion. If you select theInterpret vector parameters as 1-Dcheck box and the numeric parameters are row or column vectors after scalar expansion, the block outputs a 1-D signal. If you clear theInterpret vector parameters as 1-Dcheck box, the block outputs a signal of the same dimensionality as the parameters.
Data Type Support
The Random Number block outputs a real signal of typedouble
. For more information, seeData Types Supported by Simulinkin the Simulink®documentation.
Parameters
- Mean
-
Specify the mean of the random numbers. The default is
0
. - Variance
-
Specify the variance of the random numbers. The default is
1
. - Seed
-
Specify the starting seed for the random number generator. The default is
0
.The seed must be 0 or a positive integer. Output is repeatable for a given seed.
- Sample time
-
Specify the time interval between samples. The default is
0.1
, which matches the default sample time of theBand-Limited White Noiseblock. SeeSpecify Sample Timein the Simulink documentation for more information. - Interpret vector parameters as 1-D
-
If you select this check box and the other parameters are row or column vectors after scalar expansion, the block outputs a 1-D signal. Otherwise, the block outputs a signal of the same dimensionality as the other parameters. For more information, seeDetermining the Output Dimensions of Source Blocksin the Simulink documentation.
Characteristics
Data Types |
Double |
Sample Time |
Specified in theSample timeparameter |
Multidimensional Signals |
Yes |
Variable-Size Signals |
No |
Zero-Crossing Detection |
No |
Code Generation |
Yes |
The generator algorithm is identical to the one used in MATLAB Version 4.0 by therand
和randn
functions. For details on themcg16807
algorithm, seeChoosing a Random Number Generator(MATLAB) in the MATLAB®documentation.
To use other algorithms supported by MATLAB in a Simulink model, generate a stream of random numbers in MATLAB, and store the output as a .mat file. Use this .mat file as the random number input for your simulation. For more information, seeCreating and Controlling a Random Number Stream(MATLAB). To create multiple independent streams using MATLAB, seeMultiple Streams(MATLAB).
Note
Using multiple seeds to generate multiple parallel independent streams for a generator algorithm is not recommended for themcg16807
algorithm. Instead, use the method described above.