Code
on *:text:!pick *:#:{
  msg # $gettok($2-,$rand(1,$numtok($2-,44)),44)
}


To help you understand how this works:

$2- is everything after !pick, so in your example $2- will contain "a, b, c, d"

$numtok($2-,44) - the "44" is the ASCII character code for a comma. This is telling the script to count how many "tokens" there are separated by a comma. The result in your example will be 4, because "a", "b", "c" and "d" are each a token separated by a comma.

$rand(1,$numtok($2-,44)) tells the script to generatea random number between 1 and the number of comma-separated tokens. In your example this will select a random number between 1 and 4.

This is then placed into a $gettok():

$gettok($2-,$rand(1,$numtok($2-,44)),44) - this tells the script to select a random comma-separated token. The first argument is the text you want to extract a token from (in this case - $2- - i.e. everything after "!pick"), the second argument is the number token you want to get (in this case a random number between 1 and the number of comma-separated tokens), and the final argument is the ASCII value for the character which separates the tokens (in this case - 44 - a comma).

If you can be bothered you might prefer to do something like this as it's more readable when you write a lot of code:

Code
on *:text:!pick *:#:{
  var %tokens = $2-, %randomnumber = $rand(1,$numtok(%tokens,44)), %randomtoken = $gettok(%tokens,%randomnumber,44)
  msg # %randomtoken
}


This uses variables with descriptive names to show you what each variable is being set to. When you return to a large complex script long after you have written it, it can assist you if you use variables with descriptive names throughout your code.

A different way of doing this is to just use parameter identifiers without bothering with $gettok:

Code
on *:text:!pick *:#:{
  tokenize 44 $2- 
  msg # $eval($ $+ $rand(1,$0),2)
}


This is a bit complicated to explain if you're new to scripting, but just showing you there are many methods to accomplish the same thing.

Hope that makes sense.

Last edited by hixxy; 21/11/19 10:24 PM.