mapping to a specific range
Would it be possible to extend any of these, I'm working with exponential now, to be able to specify a range? I know lodash has _.clamp which just cuts off the numbers above and below, but then you have a lot of repeated numbers.
Thanks.
Exponential distributions go from zero to infinity. If the number is outside of the range you want, you could just discard it and pick another. However that would no longer strictly be a exponential distribution.
Perhaps if you explain what you are using the numbers for I can advise a better way.
I'm trying to use it to control musical parameters. In the SuperCollider programing langauge, used for composing music. There is a function that returns random values that follow an exponential distribution. The function has a low and high parameter so you can specify that you want a range of 0.0001 to 1 or whatever and I guess the distribution is scaled somehow to be useable though the code is for that part is precompiled in C++ and I can't find the source.
I would like to do something like this:
const exponential = Prob.exponential(1);
function mapRange(from, to, s) {
return to[0] + (s - from[0]) * (to[1] - to[0]) / (from[1] - from[0]);
}
//([fromRange],[toRange], input)
const range = mapRange([0, 10], [0, 1], exponential());
console.log(range);
But I know that isn't totally correct because fromRange should be 0 to Infinity but that isn't' valid. Let me try to figure out how they did it. Thanks for your quick reply though.