# exponential random

i’m working on an exponential random function to be released as an addon.

i’ve been using the function

``````
x = log(1-u)/(??)

``````

where u is a random number between 0.0 and 1.0 and lambda, which adjusts the distribution range, is by default 1.0.

what’s really missing is the ability to set the range, as you would with ofRandom(float min, float max).

this isn’t as straightforward tho, as the above code outputs values from 0.0 to about 15.5. my brute force method of doing this would be to scale the normalize result from the function and multiple it by the range. but is there a more accurate way to do this?

thx++

jeremy

Could you instead use the sigmoid/logistic function http://en.wikipedia.org/wiki/Sigmoid-function then ofMap? something like ofMap(sigmoid(x), 0, 1, min, max) ?

you can’t put a range on an exponential distribution, since it gives values from [0,Infinity).–
you-can-also-use–log(u)/?-to-generate-the-distribution,-see-http://en.wikipedia.org/wiki/Exponential-distribution#Generating-exponential-variates

I’m not sure it makes too much sense to publish this as an addon, since it should be very little code. I’m planning to PR some more random functions soon, so if you’re a bit patient it will land in OF itself. see https://github.com/openframeworks/openFrameworks/issues/224 and http://forum.openframeworks.cc/t/normal-gaussian-random-generator/11469/1

hey map,

thanks for this. i think that’d be closer to a gaussian distribution tho. still very useful.

bilderbuchi,

it’s true, the function can result in infinity. so clamping it at a reasonably high level isn’t exactly accurate, but the results are still very useful. can you think of anything similar that could do the trick?

yes, i was thinking exponential random with a few other random distributions (but even just having something available and handy as an addon, would encourage people to use it). it’d be great to see some more flavors of random in OF, for sure … i’ll keep my eyes peeled.

now, i’m curious to see how programs like supercollider and maxmsp handle this.

check this out, there already an addon for gaussian random. it’s ~30 lines of code…
https://github.com/andyr0id/ofxGaussian

if you are looking for probability distributions on a finite interval (i.e. a finite “support”), look here: http://en.wikipedia.org/wiki/List-of-probability-distributions#Supported-on-a-bounded-interval