## externals, table & random number

Sep 03 2013 | 1:07 pm
Hi,
How can i get the same behavior (inside an external) than a table that would be banged ? (the table outs a random number, but the probability of appearance of this number is weigthed by the values inside the table).
In fact the question should be : what kind of operations are done inside the table object when it's banged.
Thanks !

• Sep 03 2013 | 2:29 pm
If you look up the 'bang' message to table in the manual (and follow where it leads you) you'll find the answer.
• Sep 04 2013 | 8:40 am
• Sep 04 2013 | 12:08 pm
Well i fact i was looking for a way to do it in C, in my external, but thanks anyway.
I should answer my question myself now, after a day of thinking here's what i wrote :
int plussz_cherche_table(t_plussz *x){
long **data = NULL; long i, size , sum =0, rand_nb = 0,temp = 0,result = 0,indice =0;
if (!table_get(gensym("modes_majeur_5"), &data, &size)) {
for (i = 0; i < size; i++) { sum = sum+(long)(*data)[i]; }
if(sum == 0){return(-1);} else{rand_nb = rand()%(100*sum)+1;} //indice = indice+(long)(*data)[0]*100;
for(i = 0; i indice = indice+(long)(*data)[i]*100; //post("temp = %ld indice = %ld rand = %ld",temp,indice,rand_nb); if( temp < rand_nb && rand_nb < indice){ result = i; break; } else{ temp = temp + (long)(*data)[i]*100; } }//for
}//if table existe return result;
}//plussz_cherche_table
• Sep 04 2013 | 12:14 pm
So the table "modes_majeur_5" is in the patcher but my object can see it. Now this function looks for all the values in the table and picks one of them according to their probability.
If someone see something faster... let me know !
Yipee ;)
• Sep 04 2013 | 12:31 pm
I should answer my question myself now, after a day of thinking
Somehow I was under the impression that your question was "what kind of operations are done inside the table object when it’s banged."
Chris pointed to the reference doc and I made a patch that illustrated what you would have found in the documentation had you looked. Specifically, when you bang a table object, it generates a random number between 0 and 32,768, multiplies it by the sum of the numbers in the table, divides the result by 2^15 and uses that number to look up the corresponding value in the table. Glad everything worked out for you. Good luck with your project.
• Sep 04 2013 | 3:05 pm
Well,
I'm sorry that my skills in english sometimes make my sentences look like reproaches, it is not my intention.
In fact i looked at the help without even thinking about looking in the reference. I've just saw what you were talking about. So my fault...
• Sep 04 2013 | 3:05 pm
and thanks !
• Sep 04 2013 | 11:34 pm
I’m sorry that my skills in english sometimes make my sentences look like reproaches, it is not my intention.
Well.. no need to apologize. I suppose I did presume a certain degree of reproach but nothing major.. and I'm just as responsible for my assumptions.
re: help/reference.. Reference is really the 'goto' resource for detailed inquiry. Help should probably be called 'quickstart' or 'examples'. The 'see also' section in the reference tab of the sidebar usually has a link to the tutorial related to the object selected in the patcher. Tutorials are also more informative than 'help' and they contain additional patchers with more in-depth examples.