Controlling the probability

encoder audio's icon

Hi Guys,

I'm working on a new patch, where the centre is a random generator.
I generates random numbers between 0 and 10.
Is it possible somehow to control the probability of the numbers? I mean, with a multislider maybe...you could set, for example, that the probability of that the next number will 0 is, let's say 30%, but 50% that it is gonna be 7.

double_UG's icon

look at [Itable] and Tutorial 17 ( Create probability distributions)

Christopher Dobrian's icon
encoder audio's icon

Thanks guys, almost there.

Max Patch
Copy patch and select New From Clipboard in Max.

Now, is it possible to avoid repetition somehow?
I mean, like with [urn].

encoder audio's icon

Some progress here, thanks to the RTC toolbox :

Max Patch
Copy patch and select New From Clipboard in Max.


The problem is that the IF causes stack overflow if there is only 1 number :S

double_UG's icon

..

Max Patch
Copy patch and select New From Clipboard in Max.

encoder audio's icon

Stack overflow immediately :(

double_UG's icon

stack overflow is when all prob. = 0 or one only one prob is higher the others = 0,

Max Patch
Copy patch and select New From Clipboard in Max.

encoder audio's icon

Oh, yes, I see, yeah, in that way it works!!!
But...
Still not there. Maybe it's because of my english...
So, an example.

If probs for 0 and 1 are 100% (the rest 0), it should switch between 0 and 1.

double_UG's icon

...

Max Patch
Copy patch and select New From Clipboard in Max.

encoder audio's icon

Yap, thats right, in example two. But if the prob for 5 and 2 are both 100% it should generate 5-2-5-2-5-2-5-2-5, not?

Roman Thilenius's icon

if the prob for 2 and 5 are both 100% that makes a total of 200%.

not sure what others recommended above, but i would generate random numbers between 1-100000, then set the probability per number by [split 33.55 57.01], then do [/ 10000.]

Peter McCulloch's icon

There are two rules in play here:

  1. Pick a random number with a weight

  2. Avoid choosing the same number consecutively.

Picking a random number and then testing if it has been already used (and then picking a random number and then testing if it has been already used...) can easily lead to a stack overflow.

If, on the other hand, you temporarily zero out the weight for the last chosen value, you can't pick it to begin with. (You'd need to restore it afterwards of course!)