Forums > MaxMSP

Very bad random?

June 19, 2012 | 4:11 pm

Hi guys,

I surely must do something wrong… Max’s [random] cannot be that bad…
Does anyone have a clue about what I’m doing wrong in this patch? (ratio should asymptotically go to 0.2, but it doesn’t – at all…)
It happens both in Max 5 and Max 6.


— Pasted Max Patch, click to expand. —
June 19, 2012 | 5:30 pm

Interesting. I have a couple of ways of getting similar results. However, the histogram is pretty flat.

— Pasted Max Patch, click to expand. —
June 19, 2012 | 6:11 pm


Your patch calculates the ratio of values less than 0.2 vs. values greater 0.2 in the range of 0..1.
At equal distribution this ratio should be 20% vs. 80%, ie. 20/80 = 0.25 (!)
So there is nothing wrong with [random].

June 19, 2012 | 6:37 pm

random() isn’t a great RNG, but that’s not the problem.

Your patch is comparing the number of values < 0.2 with the number of values > 0.2. Ideally, that will approach the ration 0.2 : 0.8. Which is, the last time I looked, 0.25.

If you want to get something approaching 0.2, you need to compare the count of bangs coming out of your [sel 1] against a count of bangs coming out of your [< 0.2] object (the latter could also be a count of bangs coming straight out of your qmetro, btw).

There is an additional, albeit very slight, potential skew in your calculations from the fact that you only trigger the division when [< 0.2] evaluates to true. You should probably divide on every new random derivate (ie, put a [pak] in front of the [/] object).

Here is a modified patch that does what you want. For comparison, on the right there is a version using Litter Power objects. If you don’t have Litter Power, they won’t instantiate. But you can still see the modified core patch, which keeps itself to bog-standard objects.

— Pasted Max Patch, click to expand. —
June 19, 2012 | 7:58 pm

Excellent. I knew I was looking in the wrong place.

In this case, I should have been in the kitchen, looking for coffee.

June 20, 2012 | 10:22 am

Of course…
what an stupid mistake!
Sorry for posting, and thanks for answering.


June 22, 2012 | 10:50 am

Actually, an easy mistake to make. And, once made, tricky to track down. It took me a few minutes. But once I’d made a version of your patch with a RNG that I know and trust ;-) I knew the problem had to be elsewhere.

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

Forums > MaxMSP