Very bad random?

danieleghisi's icon

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.

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

Thanks,
Daniele

mzed's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

broc's icon

@Daniele

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].

Peter Castine's icon

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).

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

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.

mzed's icon

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

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

danieleghisi's icon

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

d

Peter Castine's icon

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.