Welcome to %s forums

BrainModular Users Forum

Login Register

Script "Data Generator" generates even without a trigger

General Discussion about whatever fits..
Post Reply
Charlie O.
New member
Posts: 8
Contact:

Script "Data Generator" generates even without a trigger

Unread post by Charlie O. » 20 Jan 2026, 22:33

Hi everyone,

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;

Thank's a lot !

BM2F
New member
Posts: 6
Contact:

Unread post by BM2F » 21 Jan 2026, 10:52

Hello Charlie O.

The issue was in Callback, the script compute whatever parameters changed.
You can solve it with a pass before input script (triggered by you generate trigger)
or modifie the script :

Happy patching !

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 = 3;
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

if N <> Randomiz then exit
else
   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;

Charlie O.
New member
Posts: 8
Contact:

Unread post by Charlie O. » 21 Jan 2026, 14:10

Hi, thank's a lot.
yes, that's what i did, filtering the unwanted random events, but that was not very efficient.

I have had to changed two lines, otherwise the script would not compile : line 40 "can't assign int32 to array of int32

I just added [ i ] to the line 40 : ArrayOut[ i ] := CreateParam('array out '+intTostr(i),ptArray,pioOutput);

and the next one 41, see below

HERE IS THE PROBLEM : the forum can't display the [ i ] correctly (without spaces), so it probably disapeared in the code of your message, and the script couldn't compile in my session.

If i add [ i ] (without space) in my script, now it works as it should.

I'm not sure i'm very clear, but there is a problem in the display of the forum.

Anyway thanks a lot mate !

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] *****problem**** := CreateParam('array out '+intTostr(i),ptArray,pioOutput);
ArrayOut[i]*****problem**** .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

if N <> Randomiz then exit
else
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;

BM2F
New member
Posts: 6
Contact:

Unread post by BM2F » 21 Jan 2026, 15:05

I have already modify the script look at Callback section
With mine if a other input than Rendomiz change I stop the process

No problem !

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 22 Jan 2026, 08:31

please use the "code" tag

Code: Select all

 
to paste script !

User avatar
oli_lab
Member
Posts: 1238
Location: Brittany, France
Contact:

Unread post by oli_lab » 22 Jan 2026, 10:28

Hi,
wasn't working, so I took the old code from the Usine distro and just add one line :

Code: Select all

if N <> Randomiz then exit //outputs will change only if trig arise
else
so the whole thing is :

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 = 3;
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
if N <> Randomiz then exit //outputs will change only if trig arise
else
   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;
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests