This is a development topic.
There have been discussions about having a way of conveniently normalising weights for random choice. Since the first option modifies a common method, it is discussed here.
Here is an updated collection of options.
Normalising them in wchoose
is not good, because it will do this normalisation for each new random value, which is a waste of energy (though see 2b below).
Note that I have allowed myself to add/remove as a way to reap the results of the discussion, if youād like a particular option to appear here, please let me know. I always leave the numbers to keep the reference for the discussion intact.
// 1.
choose(unnormalizedWeights) // uses weights if not nil, then normalises
wchoose(weights) // stays as now, you have to normalise yourself
- pro: no extra method / the common method is extended / simple / other languages do this / low friction from choose
- con: breaks with existing logic / suggests an inefficient method as default / needs explanation
// 1b.
// both normalise if flag is true, defaults differ
choose(weights, normalize=true) // without weights
wchoose(weights, normalize=false)// normalises if flag is true, off by default (like the TWChoose ugen)
pro: separates concerns / symmetric
con: suggests an inefficient method as default
// 2.
choose // without weights
wchoose(weights) // stays as now, you have to normalise yourself
wchooseN(normalizedWeights) // normalises
pro: separates concerns / logical and idiomatic / most efficient
con: extra method / two modification steps away from choose (front and end, alternative name: wnchoose is better, but less discoverable)
// 2b
choose // without weights
wchoose(normalizedWeights) ) // normalises
wchooseN(weights) you have to normalise yourself
this assumes that normalisation is very efficient and only matters for very large arrays
pro: separates concerns / logical and idiomatic
con: extra method / may make some existing code less efficient or break for ear tuned pieces
// 3.
choose // without weights
wchoose(weights, normalize=false) // normalises if flag is true, off by default (like the TWChoose ugen)
pro: separates concerns / logical and idiomatic
con: not easy to read in code