Main Content

Random Integer Generator

Generate integers randomly distributed in specified range

  • Random Integer Generator block

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], whereMis specified by theSet sizeparameter. Use this block to generate random binary-valued or integer-valued data.

To ensure that the model uses different initial seeds, set theSimulate usingparameter toInterpreted execution, and run the simulation in Normal or Accelerator mode. For more information, seeLimitations

Examples

expand all

Demonstrate that theRandom Integer Generatorsequences output when the initial seed source isAutoare different and that when the initial seed source isParameterthe sequences are repeatable when the seed is not changed.

Run theslex_rng_seed_sourcemodel twice and compare the output sequence.

6 1 7 7 1 7 7 3 5 6 0 1 2 3 4 7 7 6 7 7

Change the最初的种子sourcetoParameter。Run theslex_rng_seed_sourcemodel twice with the seed value set to0and compare the output sequence.

6 6 7 7 1 1 7 7 5 5 0 0 2 2 4 4 7 7 7 7

Change seed value to1993, rerun, and compare sequence to the previous sequences.

6 6 0 7 7 1 1 1 7 7 7 2 5 5 1 0 0 1 2 2 4 4 4 5 7 7 4 7 7 1

Apply QPSK modulation to a signal of random data. Pass the modulated signal through an AWGN channel. Plot the signal constellation.

Thedoc_qpsk_modmodel generates QPSK data, applies white noise, and displays the resulting constellation diagram.

Run the model with the Eb/N0 of the AWGN Channel block set to 15db.

Change the Eb/N0 from 15 dB to 10 dB. The noise level increases as shown by the greater distance between the samples.

Thecm_ex_viterbi_decode_binary_seqmodel generates a binary sequence using theRandom Integer Generatorblock. The sequence is encoded with theConvolutional Encoderblock and then impaired with theBinary Symmetric Channelblock. TheViterbi Decoderblock decodes the data sequence and the bit error rate is computed.

TheInitFcncallback is used to initialize workspace parameters for samples per frame, BSC error probability, and the Viterbi decoder traceback depth. The signal delay between the transmitted and received signal is equal to the traceback depth. The signal delay is needed for the error rate calculation.

To produce a binary bit stream, theRandom Integer Generatorblock specifies a set size of2, and output type ofboolean

The computed error rate approximates theError probabilityspecified in theBinary Symmetric Channelblock.

Computed error rate = 0.095023

Limitations

For more information, seeChoosing a Simulation Mode(Simulink)

Ports

Output

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 theOutput data typeparameter.

The number of rows in the output data equals the value of theSamples per frameparameter and corresponds to the number of samples in one frame. The number of columns in the output data equals the number of elements in theSet size参数和对应通道的数量s.

Parameters

expand all

To edit block parameters interactively, use theProperty Inspector。From the Simulink®Toolstrip, on theSimulationtab, in thePreparegallery, selectProperty Inspector

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 inSet sizecorresponds to the number of independent channels output from the block.

  • IfSet sizeis a scalar, then all output random variables are independent and identically distributed (i.i.d.).

  • IfSet sizeis 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最初的种子

最初的种子value for the random number generator, specified as a nonnegative integer. If the最初的种子parameter is a constant, then the resulting sequence is repeatable.

Dependencies

To enable this parameter, set theSource of initial seedparameter toParameter

Positive scalars specify the time in seconds between each sample of the output signal. If you set theSample timeto-1, the output signal inherits the sample time from downstream. For information on the relationship between theSample timeandSamples per frameparameters, seeSample Timing

Samples per frame, specified as a positive integer indicating the number of samples per frame in one channel of the output data. For information on the relationship betweenSample timeandSamples per frame, seeSample Timing

Output data type, specified asdouble,single,uint8,uint16,uint32, orboolean。如果这个参数设置为boolean, you must set theSet sizeparameter to2

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. InInterpreted executionmode, you can debug the source code of the block.

Block Characteristics

Data Types

Boolean|double|integer|single

Multidimensional Signals

no

Variable-Size Signals

no

More About

expand all

Extended Capabilities

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

Version History

Introduced before R2006a

expand all

See Also

Functions