Random Value + Deviation Factor
Hey everyone,
I’m working on this patch (below) where I want to randomise the current values of a multislider using an integer to set the deviation percentage (0% = no deviation, 100% = full-range deviation). The multislider’s range is variable (min 0, max adjustable). The patch I’ve attached is working okay, but the issue is that the values tend to drop to 0 and stop moving. I think it might be a float vs. integer issue...
Deviation works fine when the multislider range is set to 0. - 100. (floating-point), but if I change the range, I need to rescale the deviation percentage. For example, if the multislider range is 0. - 5., 100% deviation currently creates values from 0 - 100, when it should stay within 0 - 5 (and say i have value 5 to randomise 100% the other values are <5, instead of ±5).
I also tried another way using prepend range to random, but noticed that with other max versions i get the message that "random doesn't understand range"...
Any ideas on how to make the deviation percentage proportional to the variable range and avoid values clustering at 0?
Thanks!
Not sure I understand entirely what you want, but here is my interpretation of it:
multislider has a range of 0 - maxvalue
I could use the recent @range attribute of random but did not as you seem to use older versions of Max.
All the math is in the [vexpr]
I scale the value of random from 0 - 2000 to -1. - +1.
then I multiply the result by maxvalue and the deviation factor
and finally I add this to the previous value of the slider.
I would keep multislider at fixed range
and only fiddle with it's output.
@TFL That seems about it! The explanation makes sense. Not sure why my patch kept sending values to 0 after several bangs to random though. Thanks so much!!
sorry back to this again. @TFL approach is good with 4 sliders but was wondering how could this work with variable sliders count? say from 2 up to 500...
Here a quick edit of my last patch:
It's a bit finicky when you change the number of sliders though.
By default, zl objects handle up to lists of lenght 256. I've raised that size up to 500, but you'll need to change that if you want to go beyond 500.
had a mistake in init post ...

yes, that's it! nice one