Bernoulli Binary Generator
Generate Bernoulli-distributed random binary numbers
Communications Toolbox / Comm Sources / Random Data Sources
The Bernoulli Binary Generator block generates random binary numbers using a Bernoulli distribution. Use this block to generate random data bits to simulate digital communication systems and obtain performance metrics such as bit error rate. The Bernoulli distribution with parameter p produces zero with probability p and one with probability 1-p. The Bernoulli distribution has mean value 1-p and variance p(1-p). The Probability of zero parameter specifies p and can be any real number in range [0, 1].
The output signal can be a column or row vector, two-dimensional matrix, or scalar. The number of rows in the output signal corresponds to the number of samples in one frame and is set by the Samples per frame parameter. The number of columns in the output signal corresponds to the number of channels and is set by the number of elements in the Probability of zero parameter. For more details, see Sources and Sinks in Communications Toolbox™ User's Guide
Out — Output data signal
scalar | vector | matrix
Output data signal, returned as a scalar, vector, or matrix.
Probability of zero — Probability of generating zero at output
0.5 (default) | integer in the range [0, 1] | vector of integers in the range [0, 1]
Probability of zero must be in the range of [0, 1]. The number of elements in the Probability of zero parameter corresponds to the number of independent channels output from the block. The Bernoulli distribution with parameter p produces zero with probability p and one with probability 1-p.
Source of initial seed — Source of initial seed for random number generator
Auto (default) |
Parameter to use the Initial seed parameter to specify the initial seed for the random number generator.
When the Source of initial seed parameter is set to
Auto and the Simulate using parameter is set to
Code generation, the random number generator uses an initial seed of zero. In this case, the block generates the same random numbers each time it is started. To ensure that the model uses different initial seeds, set Simulate using parameter to
Interpreted execution. If you run
Interpreted execution in
Rapid accelerator mode, then the model behaves the same as
Code generation mode.
Initial seed — Initial seed for random number generator
If you set the Initial seed parameter to a constant value, then the resulting sequence is repeatable.
To enable this parameter, set the Source of initial seed to
Sample time — Sample time of output signal
1 (default) | -1 | positive scalar
Positive scalars specify the time in seconds between each
sample of the output signal. If you set the Sample time to
-1, the output signal inherits the sample time from downstream. For
information on the relationship between the Sample time and
Samples per frame parameters, see
Samples per frame — Samples per frame of output signal
1 (default) | positive scalar
Samples per frame in one channel of the output signal, specified as a positive integer. For information on the relationship between Sample time and Samples per frame, see Sample Timing.
Output data type — Data type of output signal
double (default) |
Select the data type for the output signal.
Simulate using — Type of simulation to run
Code generation (default) |
Type of simulation to run, specified as
Code generation or
Code generation— Simulate the model by 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 unless the model changes. This option requires additional startup time, but the speed of the subsequent simulations is faster than
Interpreted execution— Simulate the model by using the MATLAB® interpreter. This option requires less startup time than the
Code generationoption, but the speed of subsequent simulations is slower. In this mode, you can debug the source code of the block.
The time between output updates is equal to the product of the
Samples per frame and Sample time parameter
values. For example, if Sample time and Samples per
frame each equal
1, the block outputs a sample every
second. If you increase Samples per frame to 10, then the block outputs
a 10-by-1 vector every 10 seconds. This ensures that the equivalent output rate is not
dependent on the Samples per frame parameter.
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version HistoryIntroduced before R2006a
R2020a: Bernoulli Binary Generator block update supported in Upgrade Advisor
Starting in R2020a, Bernoulli Binary Generator block allows you to use the Upgrade Advisor. You can update to the block version announced in R2015b or keep the block version available before R2015b.
Use the Upgrade Advisor to update existing models that include the Bernoulli Binary Generator block.
Behavior of the random number generator is changed. The statistics are improved. For more information, see Source blocks output frames of contiguous time samples but do not use the frame attribute in the R2015b Release Notes.