Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapping to a specific range #2

Open
tatecarson opened this issue Jul 9, 2017 · 2 comments
Open

mapping to a specific range #2

tatecarson opened this issue Jul 9, 2017 · 2 comments
Labels

Comments

@tatecarson
Copy link

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.

@bramp
Copy link
Owner

bramp commented Jul 9, 2017

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.

@bramp bramp added the question label Jul 9, 2017
@tatecarson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants