Created
August 29, 2020 14:54
-
-
Save madskjeldgaard/19dc8329a3b22dfb651a4fb1d4b35729 to your computer and use it in GitHub Desktop.
Titled weights example SuperCollider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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