![]() |
![]() ![]() ![]() ![]() ![]()
|
next newest topic | next oldest topic |
Author | Topic: Randomly select from a subset of a collection | |
SSC Administrator |
![]() ![]() ![]() Q: I would like to randomly select from a collection of values. But I would like to be able to eliminate some of the values from consideration, based on switches or toggles that I control from the VCS. A: If you paste the following code into a SoundToGlobalController, it will generate indexes of randomly selected switches, choosing ONLY from among those switches that are currently turned ON. Then you can use these index values to look up other values from an array. For the code, please see the tweaky: http://www.symbolicsound.com/cgi-bin/bin/view/How/RandomSelectFromSubset IP: Logged | |
JackRosete Member |
![]() ![]() ![]() Great code! Found a Smalltalk resource on the web that explains some of the more esoteric code, like inject: into: etc. http://www.ifi.unizh.ch/richter/Classes/oose2/01_Collections/03_smalltalk/03_smalltalk.html#4%20Using%20inject:into: IP: Logged | |
SSC Administrator |
![]() ![]() ![]() See also page 379 of Kyma X Revealed: "Messages for iterating over the contents of collections" IP: Logged | |
cristian_vogel Member |
![]() ![]() ![]() i was working on this variation , which steps through only the switches that are on, rather than jumping randomly around them. | ctrls index count step expr tick | ctrls := {(1 to: 8) collect: [ :i | !sw suffix2: i]}. index := EventVariable new. tick := 1 bpm: !BPM. count := ctrls inject: 0 into: [ :a :b | a + b asLogicValue]. step := tick countTriggersMod: count. expr := (index <+ (step + 1)), 0.
expr It works fine, but there is often a rhythm jump when a switch comes in and out - I wanted to make it only execute the block count := ctrls inject: 0 into: [ :a :b | a + b asLogicValue]. if tick was on the positive edge of its trigger cycle - but I ran up against ' HotVariables cannot ... ' every time I tried to make a conditional to check the status of the tick ( whether logic high or low ) Could SSC suggest a way of doing this? IP: Logged | |
cristian_vogel Member |
![]() ![]() ![]()
IP: Logged | |
SSC Administrator |
![]() ![]() ![]() | ctrls index count step expr tick | index := EventVariable new.
[This message has been edited by SSC (edited 08 January 2007).] IP: Logged |
All times are CT (US) | next newest topic | next oldest topic |
![]() ![]() |
This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.