ArrayArrayArray
BrainModularBrainModular Users Forum2014-08-15T23:23:20+02:00https://brainmodular.org/forums/app.php/feed/topic/45112014-08-15T23:23:20+02:002014-08-15T23:23:20+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30231#p30231Statistics: Posted by senso — 15 Aug 2014, 23:23
]]>
2014-08-15T15:45:46+02:002014-08-15T15:45:46+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30230#p30230Iwas trying to do a draft from a hat, or a random sequence from an array input
planned to be used in shuffling midi notes and/or button fonction at random (when used with a mapper data....)
<code> ////////////////////////// // shuffle array ///////////////////////// // parameters declaration var ArrIn : TParameter; var ArrOut : TParameter; var Shuffle : TParameter; Var Memo : TParameter; // initialisation : create parameters procedure init; var i : integer; begin ArrIn := CreateParam('in',PtArray); SetIsOutput(ArrIn,false); SetMax(ArrIn,MAXINT);
// Callback procedure Procedure Callback(N:integer); var l,j,index : integer; var v : single; begin case n of 1:begin //do shuffle l := GetLength(ArrIn); SetLength(ArrOut,l); SetLength(Memo,l);
l := l - 1;
for j := 0 to l do begin SetDataArrayValue (Memo,j,GetDataArrayValue(ArrIn, j)); end;
for j := 0 to l-1 do begin //tirer un nombre (index) entre 0 et la taille du sac - i (l-i)ce sera l'index du nombre à mettre dans la table de sortie index := random(l-j); //placer ce nombre dans la table de sortie à l'index j SetDataArrayValue (ArrOut,l-j,GetDataArrayValue(Memo, index)); //donner la valeur du dernier nombre de la table (à l'index j) à la position index SetDataArrayValue (Memo,index,GetDataArrayValue(Memo, l-j)); //reduire la table d'entrée de 1 end; //end for //si la table est de taille >1, recommencer. //si la table est de taille <= 1, placer le nombre à l'index 0 dans l'index l de la table de sortie, SetDataArrayValue (ArrOut,0,GetDataArrayValue(Memo,0)); // c'est fini
end; //end do shuffle
end; //case end;
// Global variables
////////////////////////////// // main proc ////////////////////////////// Procedure Process; begin
end;
</code>
Statistics: Posted by oli_lab — 15 Aug 2014, 15:45
]]>2014-08-14T22:28:42+02:002014-08-14T22:28:42+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30224#p30224I need To use a random array with a bunch of numbers that are all unique ! For exemple I need 30 numbers from 1 to 30 With no réplication
Just lire you drap numbers from a bag...
Anyone has already build such à random generator ?
Statistics: Posted by oli_lab — 14 Aug 2014, 22:28
]]>BrainModularBrainModular Users Forum2014-08-15T23:23:20+02:00https://brainmodular.org/forums/app.php/feed/topic/45112014-08-15T23:23:20+02:002014-08-15T23:23:20+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30231#p30231Statistics: Posted by senso — 15 Aug 2014, 23:23
]]>2014-08-15T15:45:46+02:002014-08-15T15:45:46+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30230#p30230Iwas trying to do a draft from a hat, or a random sequence from an array input
planned to be used in shuffling midi notes and/or button fonction at random (when used with a mapper data....)
<code> ////////////////////////// // shuffle array ///////////////////////// // parameters declaration var ArrIn : TParameter; var ArrOut : TParameter; var Shuffle : TParameter; Var Memo : TParameter; // initialisation : create parameters procedure init; var i : integer; begin ArrIn := CreateParam('in',PtArray); SetIsOutput(ArrIn,false); SetMax(ArrIn,MAXINT);
// Callback procedure Procedure Callback(N:integer); var l,j,index : integer; var v : single; begin case n of 1:begin //do shuffle l := GetLength(ArrIn); SetLength(ArrOut,l); SetLength(Memo,l);
l := l - 1;
for j := 0 to l do begin SetDataArrayValue (Memo,j,GetDataArrayValue(ArrIn, j)); end;
for j := 0 to l-1 do begin //tirer un nombre (index) entre 0 et la taille du sac - i (l-i)ce sera l'index du nombre à mettre dans la table de sortie index := random(l-j); //placer ce nombre dans la table de sortie à l'index j SetDataArrayValue (ArrOut,l-j,GetDataArrayValue(Memo, index)); //donner la valeur du dernier nombre de la table (à l'index j) à la position index SetDataArrayValue (Memo,index,GetDataArrayValue(Memo, l-j)); //reduire la table d'entrée de 1 end; //end for //si la table est de taille >1, recommencer. //si la table est de taille <= 1, placer le nombre à l'index 0 dans l'index l de la table de sortie, SetDataArrayValue (ArrOut,0,GetDataArrayValue(Memo,0)); // c'est fini
end; //end do shuffle
end; //case end;
// Global variables
////////////////////////////// // main proc ////////////////////////////// Procedure Process; begin
end;
</code>
Statistics: Posted by oli_lab — 15 Aug 2014, 15:45
]]>2014-08-14T22:28:42+02:002014-08-14T22:28:42+02:00https://brainmodular.org/forums/viewtopic.php?t=4511&p=30224#p30224I need To use a random array with a bunch of numbers that are all unique ! For exemple I need 30 numbers from 1 to 30 With no réplication
Just lire you drap numbers from a bag...
Anyone has already build such à random generator ?
Statistics: Posted by oli_lab — 14 Aug 2014, 22:28