Difference between revisions of "choose"

From TidalCycles userbase
Jump to: navigation, search
(add wchooseBy)
(Marked this version for translation)
Line 15: Line 15:
 
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 =
+
= chooseBy = <!--T:11-->
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>chooseBy :: Pattern Double -> [a] -> Pattern a</syntaxhighlight>
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>chooseBy :: Pattern Double -> [a] -> Pattern a</syntaxhighlight>
  
 +
<!--T:12-->
 
The '''chooseBy''' function is like [[choose]] but instead of selecting elements of the list randomly, it uses the given pattern to select elements.
 
The '''chooseBy''' function is like [[choose]] but instead of selecting elements of the list randomly, it uses the given pattern to select elements.
  
 +
<!--T:13-->
 
<source>
 
<source>
 
chooseBy "0 0.25 0.5" ["a","b","c","d"]
 
chooseBy "0 0.25 0.5" ["a","b","c","d"]
 
</source>
 
</source>
  
 +
<!--T:14-->
 
will result in the pattern '''"a b c"'''
 
will result in the pattern '''"a b c"'''
  
Line 42: Line 45:
 
''Note: prior to version 1.0.0 of tidal, the weights had to add up to 1, but this is no longer the case.''
 
''Note: prior to version 1.0.0 of tidal, the weights had to add up to 1, but this is no longer the case.''
  
= wchooseBy =
+
= wchooseBy = <!--T:15-->
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>wchooseBy :: Pattern Double -> [(a,Double)] -> Pattern a </syntaxhighlight>
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>wchooseBy :: Pattern Double -> [(a,Double)] -> Pattern a </syntaxhighlight>
  
 +
<!--T:16-->
 
The '''wchooseBy''' function is like [[wchoose]] but instead of selecting elements of the list randomly, it uses the given pattern to select elements.
 
The '''wchooseBy''' function is like [[wchoose]] but instead of selecting elements of the list randomly, it uses the given pattern to select elements.
  

Revision as of 23:53, 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.

wchooseBy

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

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