Forums > MaxMSP

random and change – help please

November 30, 2006 | 10:45 am

Hi,
Tis is probably a total newbie question but i really need your help as i have tried all the ways i can think of.

Here is my problem:
I need to generate a random number betveen 0 and 3 on each bang to random and filter the numbers so that there are no immediate repetitions ever (so just using [deal] does not work). I’m trying to do that by connecting [random] and [change]. Change filters out the repetitions nicely but i need a way to send bang to random when [change] has filtered out the int random sent so the [random] would trie automatically again until a different int is generated and change lets it pass.

Here is what i have now:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 93 195 36 9109513 print R;
#P button 93 61 15 0;
#P newex 93 150 40 9109513 Change;
#P newex 93 104 51 9109513 Random 3;
#P window linecount 3;
#P comment 114 62 100 9109513 each bang from here should generate output from change;
#P connect 2 0 4 0;
#P connect 3 0 1 0;
#P connect 1 0 2 0;
#P window clipboard copycount 5;

thanks
Taaniel


November 30, 2006 | 11:03 am

On 30 nov. 06, at 11:45, Taaniel wrote:

> Hi,
> Tis is probably a total newbie question but i really need your help
> as i have tried all the ways i can think of.
>
> Here is my problem:
> I need to generate a random number betveen 0 and 3 on each bang to
> random and filter the numbers so that there are no immediate
> repetitions ever (so just using [deal] does not work). I’m trying
> to do that by connecting [random] and [change]. Change filters out
> the repetitions nicely but i need a way to send bang to random when
> [change] has filtered out the int random sent so the [random] would
> trie automatically again until a different int is generated and
> change lets it pass.

Hi,

There’s an abstraction called "urn-jb" in the examples folder of Max.
It uses the urn object which output random numbers without
duplicates, and some "intelligence" to filter the possible repetition
at the start of a new serie.

HTH,
ej


November 30, 2006 | 11:20 am

Like this ?

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 90 97 30 196617 t b s;
#P message 114 76 33 196617 clear;
#P newex 93 195 36 196617 print R;
#P button 54 58 15 0;
#P newex 90 131 34 196617 urn 3;
#P connect 4 0 0 0;
#P connect 4 1 0 0;
#P connect 3 0 4 0;
#P fasten 0 1 3 0 119 158 156 158 156 64 119 64;
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P window clipboard copycount 5;

cheers
Roger

— Taaniel wrote:

>
>
> Here is my problem:
> I need to generate a random number betveen 0 and 3
> on each bang to random and filter the numbers so
> that there are no immediate repetitions ever (so
> just using [deal] does not work). I’m trying to do
> that by connecting [random] and [change]. Change
> filters out the repetitions nicely but i need a way
> to send bang to random when [change] has filtered
> out the int random sent so the [random] would trie
> automatically again until a different int is
> generated and change lets it pass.
>


November 30, 2006 | 1:11 pm

an annotated solution without urn

Roby

#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P comment 253 219 100 196617 2. if there’s a number then open the
door for it to pass;
#P window linecount 1;
#P newex 161 347 57 196617 route bang;
#P user gswitch2 132 304 39 32 1 0;
#P newex 199 244 29 196617 t i 1;
#P newex 161 139 87 196617 t b i 0;
#P newex 208 375 36 196617 print R;
#P button 161 54 15 0;
#P newex 199 218 40 196617 Change;
#P newex 161 106 51 196617 Random 3;
#P toggle 132 280 15 0;
#P window linecount 3;
#P comment 260 128 100 196617 1. first close the door below for the
numbers;
#P window linecount 2;
#P comment 60 137 100 196617 3. otherwise only this bang goes thru;
#P window linecount 4;
#P comment 262 344 100 196617 4. finaly we filter out the bang in the
case when there was a number;
#P fasten 10 0 4 0 137 347 115 347 115 84 166 84;
#P connect 11 1 7 0;
#P connect 10 1 11 0;
#P connect 8 0 10 1;
#P connect 9 1 3 0;
#P connect 8 2 3 0;
#P connect 4 0 8 0;
#P connect 8 1 5 0;
#P connect 5 0 9 0;
#P connect 9 0 10 1;
#P connect 3 0 10 0;
#P connect 6 0 4 0;
#P window clipboard copycount 13;

On 30 nov. 06, at 11:45, Taaniel wrote:
> Here is my problem:
> I need to generate a random number betveen 0 and 3 on each bang to
> random and filter the numbers so that there are no immediate
> repetitions ever (so just using [deal] does not work). I’m trying
> to do that by connecting [random] and [change]. Change filters out
> the repetitions nicely but i need a way to send bang to random when
> [change] has filtered out the int random sent so the [random] would
> trie automatically again until a different int is generated and
> change lets it pass.
>
> Here is what i have now:
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 93 195 36 9109513 print R;
> #P button 93 61 15 0;
> #P newex 93 150 40 9109513 Change;
> #P newex 93 104 51 9109513 Random 3;
> #P window linecount 3;
> #P comment 114 62 100 9109513 each bang from here should generate
> output from change;
> #P connect 2 0 4 0;
> #P connect 3 0 1 0;
> #P connect 1 0 2 0;
> #P window clipboard copycount 5;


November 30, 2006 | 1:38 pm

so much for your help !

Taaniel


November 30, 2006 | 6:34 pm

On Nov 30, 2006, at 5:11 AM, Roby Steinmetzer wrote:

>> I need to generate a random number betveen 0 and 3 on each bang to
>> random and filter the numbers so that there are no immediate
>> repetitions ever (so just using [deal] does not work).

I think this works…if someone finds a bug please let me know…

max v2;
#N vpatcher 264 156 813 509;
#P toggle 185 206 15 0;
#P window setfont "Sans Serif" 9.;
#P number 75 139 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 117 108 55 196617 Random 10;
#P number 117 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 117 65 15 0;
#N vpatcher 40 55 440 355;
#P window setfont "Sans Serif" 9.;
#P number 52 89 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 257 119 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N comlet int;
#P inlet 34 53 15 0;
#P newex 34 117 175 196617 if ($i1!=$i2) then $i1 else out2 bang;
#N comlet bang when a direct repetition occurs;
#P outlet 199 145 15 0;
#N comlet output without direct repetitions;
#P outlet 34 151 15 0;
#P newex 199 91 27 196617 int;
#P connect 4 0 3 0;
#P connect 3 0 1 0;
#P connect 4 0 6 0;
#P fasten 3 0 0 0 39 142 23 142 23 82 204 82;
#P connect 0 0 3 1;
#P connect 3 1 2 0;
#P connect 0 0 5 0;
#P pop;
#P newobj 117 151 78 196617 p antiRepetition;
#P fasten 3 0 4 0 122 132 80 132;
#P fasten 0 1 3 0 190 189 269 189 269 95 122 95;
#P connect 1 0 3 0;
#P connect 3 0 0 0;
#P connect 0 0 2 0;
#P connect 0 1 5 0;
#P pop;


November 30, 2006 | 9:14 pm

You can also check out "anti-bis" from RTC-lib by Karlheinz Essl.

Best,
Trond

>>> /I need to generate a random number betveen 0 and 3 on each bang to
>>> random and filter the numbers so that there are no immediate
>>> repetitions ever (so just using [deal] does not work). /
>>>


December 1, 2006 | 7:31 am

a simple arithmetic solution (uncommented)
//yac

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 264 127 32 9109513 range;
#P newex 188 156 27 9109513 – 1;
#P number 228 127 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 147 202 27 9109513 + 1;
#P number 147 302 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 147 273 32 9109513 % 10;
#P newex 147 240 30 9109513 +;
#P button 147 127 15 0;
#P newex 147 178 51 9109513 random 9;
#P comment 163 127 32 9109513 click;
#P connect 6 0 3 0;
#P connect 7 0 4 1;
#P connect 7 0 8 0;
#P connect 4 0 5 0;
#P connect 4 0 3 1;
#P connect 8 0 1 1;
#P connect 1 0 6 0;
#P connect 3 0 4 0;
#P connect 2 0 1 0;
#P window clipboard copycount 10;


December 1, 2006 | 8:30 am

try this

Lorenzo

max v2;
#N vpatcher 20 74 456 433;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 69 120 48 196617 r rebang;
#P newex 222 242 48 196617 s rebang;
#P newex 60 173 172 196617 t i b;
#P newex 222 197 27 196617 int;
#P number 60 274 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 60 221 172 196617 if $i1 != $i2 then $i1 else out2 bang;
#P newex 72 242 32 196617 print;
#P number 108 60 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 60 85 58 196617 metro 250;
#P toggle 60 60 15 0;
#P newex 120 120 48 196617 t b clear;
#P newex 60 146 34 196617 urn 4;
#P connect 2 0 3 0;
#P fasten 11 0 0 0 74 141 65 141;
#P fasten 1 0 0 0 125 141 65 141;
#P fasten 1 1 0 0 163 141 65 141;
#P connect 3 0 0 0;
#P connect 0 0 9 0;
#P connect 9 0 6 0;
#P connect 6 0 7 0;
#P connect 6 0 5 0;
#P connect 4 0 3 1;
#P fasten 0 1 1 0 89 167 174 167 174 115 125 115;
#P connect 9 1 8 0;
#P connect 8 0 6 1;
#P connect 6 1 10 0;
#P fasten 6 0 8 1 65 263 273 263 273 191 244 191;
#P pop;


December 1, 2006 | 2:25 pm

Taaniel wrote:
> Here is my problem: I need to generate a random number betveen 0 and
> 3 on each bang to random and filter the numbers so that there are no
> immediate repetitions ever (so just using [deal] does not work).

Yet another one:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 139 225 50 196617 deferlow;
#P newex 93 126 56 196617 t i i;
#P newex 139 203 30 196617 sel 1;
#P newex 139 180 30 196617 ==;
#P newex 93 180 41 196617 print R;
#P button 93 80 15 0;
#P newex 93 148 44 196617 change;
#P newex 93 104 51 196617 random 3;
#P connect 1 0 3 0;
#P connect 1 0 4 1;
#P fasten 7 0 0 0 144 248 195 248 195 100 98 100;
#P connect 5 0 7 0;
#P connect 4 0 5 0;
#P connect 6 1 4 0;
#P connect 6 0 1 0;
#P connect 0 0 6 0;
#P connect 2 0 0 0;
#P window clipboard copycount 8;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


December 4, 2006 | 5:51 pm

Yacine Sebti wrote:
> a simple arithmetic solution (uncommented)

nice one…
took a while to understand why it works…
it’s probably faster than any comparison for duplicates…

You win the price for the most elegant solution. Could be a wonderful
task for Max classes… It shows that there are a lot of very different
kind of obvious solutions, but there might be still an even more elegant
solution out there…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


Viewing 11 posts - 1 through 11 (of 11 total)