PREP 2013 Question Authoring - Archived

Re: Making variable names random

by Davide Cervone -
Number of replies: 0
There is a slightly easier way of selecting the variable name: list_random. This function returns one of its arguments chosen at random. So
    $var = list_random('w','x','y','z');  would select the variable name at random, and could replace your three-line version of doing this. [Of course, you could have done your version in only one line as well, $var = ('w','x','y','z')[random(0,3,1)];

but list_random is slightly cleaner, as you don't have to worry about knowing the number of elements in the array.]