I have a problem with one of the scripts from the Browser/Modules/Data/Generators, the "Data Generator Random Pattern Array" script. It has three inputs : Array In, Generate (trigger type), and Density (data float).
The problem is that when the density fluctuates, the module generates randoms arrays, even without a trigger.
Here is the code, if somebody has an idea and can help me how to correct it ?
Code: Select all
//////////////////////////////////////////////////////
// Random Pattern Array
// Generates a Random array of 0 or 1 values according to
// the DENSITY parameter
// Connected to a Switch Sequenced module,
// can be use to create random paterns
//////////////////////////////////////////////////////
const NB_ARRAY_OUT = 2;
var ArrayLen : Tparameter;
var Density : Tparameter;
var ArrayOut : array of Tparameter;
var Randomiz : TParameter;
//////////////////////////////////////////////////////
// initialisation procedure
//////////////////////////////////////////////////////
procedure init;
var i : integer;
begin
ArrayLen := CreateParam('array len',ptDataField,pioInput);
ArrayLen.Min(1);
ArrayLen.Max(1024);
ArrayLen.DefaultValue(8);
ArrayLen.asInteger(8);
Randomiz := CreateParam('generate',ptButton,pioInput);
Density := CreateParam('density',ptDataFader,pioInput);
Density.Symbol('%');
Density.Format('%.0f');
Density.Min(0);
Density.Max(100);
Density.DefaultValue(50);
Density.asFloat(50);
SetArraylength(ArrayOut,NB_ARRAY_OUT);
for i := 0 to NB_ARRAY_OUT-1
do begin
ArrayOut[i] := CreateParam('array out '+intTostr(i),ptArray,pioOutput);
ArrayOut[i].Length(0);
end;
ModuleColor($FFE91E63);
end;
// Global Variables
var vlen : integer;
var j,i : integer;
var vDens : single;
//////////////////////////////////////////////////////
// CallBack
//////////////////////////////////////////////////////
// Callback procedure
Procedure Callback(N:integer);
begin
vDens := Density.asFloat/100;
vlen := ArrayLen.asInteger;
for j := 0 to NB_ARRAY_OUT-1
do begin
ArrayOut[j].Length(vlen);
for i := 0 to vlen-1
do begin
if random < vDens
then ArrayOut[j].asArray(i,1)
else ArrayOut[j].asArray(i,0);
end;
end;
end;
