• ### Pick random elements from a list

Hi everyone,
I have this simple abstraction I've been using to pick numbers randomly from a list (patch: rand.list). This works fine as long as the list contains only floats, but now I need it to work with lists containing symbols as well. I'm sure it could be done with [text], but I'm trying to understand if this can be done with [array], [list tosymbol] and [list/fromsymbol]. Attached is my attempt (patch: rand.list.symbol), but it doesn't work. Actually, I can't make any sense of how those tosymbol/fromsymbol objects work so if anyone has any suggestion, I thank you very much in advance for your help.

rand.list.zip

• Posts 10 | Views 6013
• @weightless It works fine for me if I give the middle inlet of [array get] a value of 1........ you are working too hard and getting tired!
You have the tosymbol/fromsymbol correct.
Fromsymbol outputs the ascii numeric value of a symbol, and tosymbol the opposite.
If you are doing this for your recursions, it might be best to do the translations manually though.
With so little work to do "on paper"...... a=1 b=2 [=3 ]=4 etc. the patch will be much quicker just working directly with the integers......

Tested with the list message [a b c d e f g h(
David.

• @whale-av Sorry, I forgot to specify: it works as long as the symbols are 1 character long. I'm starting to think that if they are any longer than that then they are split into individual characters, and there is no way to put them back together.
Thanks for the tip, although this is for something else as well and I'd like to have a universal abstraction so I can feed it lists of any kind.

But yes I'm getting a bit tired, and the warning sign is when I start dreaming in Pd.

• @weightless Yes, in your patch only the first character of a symbol will get through because fromsymbol will output 115 <space> 101 when given [se( and so split the "symbol".
You would have to join them back up with a \$1\$2 (as a symbol) which defeats the object of the exercise, or add them together which would be equally pointless, or give them a marker using maybe negative integers added to the array(-2 = next 2 values are joined, -3 next 3 values are joined........ etc.).
But then random will be giving wrong pointers........ aaargh!
Just initial thoughts.......
David.
More thoughts.....
If you split the symbols, and add another array that keeps track of the number of characters in each and every symbol then you can control the middle inlet of [array get] to recover the correct number of characters....... probably.....

• @whale-av Thanks, I was hoping there would be a simple way to do it, but I think it's probably best to just use [text].

• Here it is done with [text], looks simple enough.

rand.list.text.zip

• @weightless A bit late..... and blatant plagiarism, but you could just save the list to a message with [add2( or [set( and then interrogate the list..........
Can be simplified if you promise not to send a negative index.....!
index.zip
David.

• @whale-av I can't open the zip but I think I got it! very ingenious, thanks David!

EDIT: wrong file

• @weightless He he....! I forgot to copy into the zip....... I am tired as well......
index.zip
David.

• Actually there is no need to even set the message. This is as simple as I can get it.

rand.list.pd

Thanks for making me think about it again, most of the time there's a simpler way to do it still.

Posts 10 | Views 6013
Internal error.

Oops! Looks like something went wrong!