Difference between revisions of "choose"

From TidalCycles userbase
Jump to: navigation, search
(Marked this version for translation)
(add chooseBy)
Line 14: Line 14:
 
<!--T:4-->
 
<!--T:4-->
 
As with all [[continuous patterns]], you have to be careful to give them structure; in this case '''chooose''' gives you an infinitely detailed stream of random choices.
 
As with all [[continuous patterns]], you have to be careful to give them structure; in this case '''chooose''' gives you an infinitely detailed stream of random choices.
 +
 +
= chooseBy =
 +
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>chooseBy :: Pattern Double -> [a] -> Pattern a</syntaxhighlight>
 +
 +
The '''chooseBy''' function is like [[choose]] but instead of selecting elements of the list randomly, it uses the given pattern to select elements.
 +
 +
<source>
 +
chooseBy "0 0.25 0.5" ["a","b","c","d"]
 +
</source>
 +
 +
will result in the pattern '''"a b c"'''
  
 
= wchoose = <!--T:5-->
 
= wchoose = <!--T:5-->

Revision as of 23:45, 5 December 2018

Type: choose :: [a] -> Pattern a

The choose function emits a stream of randomly choosen values from the given list, as a continuous pattern.

d1 $ sound "drum ~ drum drum" # n (choose [0,2,3])

As with all continuous patterns, you have to be careful to give them structure; in this case chooose gives you an infinitely detailed stream of random choices.

chooseBy

Type: chooseBy :: Pattern Double -> [a] -> Pattern a

The chooseBy function is like choose but instead of selecting elements of the list randomly, it uses the given pattern to select elements.

chooseBy "0 0.25 0.5" ["a","b","c","d"]

will result in the pattern "a b c"

wchoose

Type: wchoose :: [(a, Double)] -> Pattern a

wchoose is similar to choose, but allows you to 'weight' the choices, so some are more likely to be chosen than others. The following is similar to the previous example, but the 2 is twice as likely to be chosen than the 0 or 3.

d1 $ sound "drum ~ drum drum" # n (wchoose [(0,0.25,(2,0.5),(3,0.25)])

Note: prior to version 1.0.0 of tidal, the weights had to add up to 1, but this is no longer the case.