Skip to content

Instantly share code, notes, and snippets.

@madskjeldgaard
Created August 29, 2020 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madskjeldgaard/19dc8329a3b22dfb651a4fb1d4b35729 to your computer and use it in GitHub Desktop.
Save madskjeldgaard/19dc8329a3b22dfb651a4fb1d4b35729 to your computer and use it in GitHub Desktop.
Titled weights example SuperCollider
/*
TILTED-WEIGHTS
madskjeldgaard, 2020
https://github.com/madskjeldgaard
Tested using SuperCollider version 3.11.0
*/
(
~tiltedWeights = {| array, tilt=1.0 |
array.collect{|weight, weightNum|
weightNum.linlin(0, array.size, tilt, 1.0 - tilt )
}.normalizeSum
};
a = (1..10);
~tilt = 1.0;
~weights = ~tiltedWeights.value(a, tilt: ~tilt);
~choice = a.wchoose(~weights);
"Tilt: %".format(~tilt).postln;
"Array: %".format(a).postln;
"Weights: %".format(~weights).postln;
"Choice: %".format(~choice).postln;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment