Previous topic

Ring and Amplitude Modulation

Next topic

Bypassing with Switches

This Page

Random Number Generation

Let’s generate a sine wave whose frequency changes to a random value between 30 and 1000 Hz every 100 milliseconds for an infinite time and send the signal to audio outputs 1 and 2.

The following code are presented in compact mode.

signal FrequencyValue {
        default:        100.0
        rate:           10
}

RandomNumber (
        minimum:        30.0
        maximum:        1000.0
)
>> FrequencyValue;


Oscillator (
        type:           'Sine'
        frequency:      FrequencyValue
)
>> AudioOut[1:2];

What if we want to send different random frequencies to outputs 1 and 2?

signal FrequencyValue [2] {
        default:        100.0
        rate:           10
}

RandomNumber (
        minimum:        30.0
        maximum:        1000.0
)
>> FrequencyValue;


Oscillator (
        type:           'Sine'
        frequency:      FrequencyValue
)
>> AudioOut[1:2];

To get more random frequency oscillators on more channels, one could do the following.

constant NumberOfChannels  {
        value:          4
}

signal FrequencyValue [NumberOfChannels] {
        default:        100.0
        rate:           10
}

RandomNumber (
        minimum:        30.0
        maximum:        1000.0
)
>> FrequencyValue;


Oscillator (
        type:           'Sine'
        frequency:      FrequencyValue
)
>> AudioOut[1:NumberOfChannels];