[LON-CAPA-users] Choosing m elements out of n in an array

Guy Ashkenazi lon-capa-users@mail.lon-capa.org
Mon, 21 Feb 2005 23:33:19 +0200

I've seen several people using the following method to choose 3 
different elements out of n in an array:
while ($which1 == $which2)  {
while (($which3 == $which2) || ($which3 == $which1))  {


It is much shorter (and more legible) to use:


and then use $reaction[0], $answer[0], $reaction[1], $answer[1],... in 
the question. This method can be used for any m <= n, while the 
previous one will become more complex to write (and time consuming to 
run) as m approaches n.

Question for Guy - is there a difference between using 
&random_permutation() and &map() ?