# Use Randomized Values from a List

You can use the WebAssign pick() function in your questions to select one or more distinct items at random from a list, for example, to select three molecules from a list of simple hydrocarbons.

Best Practice Assign each randomized value to a variable. Then use the variable to perform additional computation or to display the value in the question, answer key, or solution.
1. If needed, open your question in the Question Editor.
2. In an <EQN> or <eqn> tag, use the pick() function to select distinct values from a list.
Use the following syntax:
pick(n,list)
where:
• n is the number of different values you want to select, and must be less than or equal to the number of items in list.
• list is either an array variable or a comma-delimited list of values.
Note
• Use a list of variables (in parentheses) or an array to store the values returned by pick().
• The pick() function selects the specified number of different items from the list. For example, pick(2,'a','b','c') will never return ('a','a').

However, pick(2,'a','b','b') might return ('b','b') because there are two different items in the list with a value of 'b'.

For example:

# select a single color
($a) = pick(1,'red','orange','yellow','green','blue','violet'); # select two different colors ($a,$b) = pick(2,'red','orange','yellow','green','blue','violet'); # or @a = pick(2,'red','orange','yellow','green','blue','violet'); # select two different integers between 15 and 25 ($c, $d) = pick(2,15..25); # select one, two, or four values from an array @firstprimes = (1,2,3,5,7,11,13,17,19,23); ($x)    = pick(1,@firstprimes);
($x,$y) = pick(2,@firstprimes);
@x      = pick(4,@firstprimes);

## Example Question Using pick()

The following table summarizes an actual question.

 QID 1931415 pick() example 1 Numerical  # select primes for $a and$b so students need not simplify ($a) = pick(1,7,11,13,17,19); ($b) = pick(1,61,67,71,73,79,83,89,97); @color = pick(2,'red','purple','blue','green','yellow','orange'); '' A jar contains marbles, of which are and are . If you take 1 marble out of the jar without looking, what is the probability that the marble you choose is ?
<_> 

## Example Question Using pick()

The following table summarizes an actual question.

 QID 1947949 pick() example 2 Multiple-Choice  @lanthanides = pick(3, 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu'); @distractors = pick(4, 'Actinides', 'Metalloids', 'Halogens', 'Alkali Metals', 'Alkaline earth metals', 'Transition metals', 'Noble gases'); '' The elements , , and are all:
<_> Lanthanides