Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Scroll Documents: Update page title prefix

Overview

Random number generator using a LCG algorithm

Discussion

Generates uniformly distributed random values using a linear congruential generator. The module outputs 32-bit integer values which can be interpretted as int or fract32 values. The random values occupy the entire numerical range. Integer values are in the range of [-2^31 +2^31) and fract32 values are in the range of [-1 +1).

The seed variable specifies the starting seed of the random process. After the module processes a block of data, the seed value equals the last output sample. When the module is instantiated, the seed value is randomly set by MATLAB.

Type Definition

Code Block
typedef struct _ModuleRand
{
    ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
    UINT32 seed;                                  // Initial seed value for the random number generator.
} ModuleRandClass;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

seed

uint

parameter

0

random value

Unrestricted

Pins

Output Pins

Name: out1

Description: audio output

Data type: fract32

MATLAB Usage

File Name: rand_module.m

Code Block
 M=rand_module(NAME, NUMPINS, NUMCHANNELS, BLOCKSIZE, SR, DATATYPE, ISCOMPLEX)
 Random number generator module supporting integer and fract32 signal
 types. The output signal is uncorrelated random data lying within the
 full range of the allowable signal values. Integer values are in the
 range of [-2^31 +2^31) and fract32 values are in the range of [-1 +1).
 The module supports multiple output pins in which all of the data is
 uncorrelated.
 Arguments:
    NAME - name of the module.
    NUMPINS - number of output pins.
    NUMCHANNELS - number of interleaved channels in each output pin.
    BLOCKSIZE - number of samples per output channel.
    SR - sample rate of the output.
    DATATYPE - string specifying either, 'int' or 'fract32'.
    ISCOMPLEX - boolean that indicates complex data.

...