Annotation of loncom/html/adm/help/tex/Authoring_Daxe_Variables.tex, revision 1.1
1.1 ! raeburn 1: \label{Authoring_Daxe_Variables}
! 2:
! 3: \textbf{Creating a Problem with Randomized Values}
! 4:
! 5: Some randomization can easily be achieved with a radio button response,
! 6: by setting thei\texttt{randomize} attribute to 'yes', setting the
! 7: \texttt{max} attribute to a maximum number of displayed foils,
! 8: and creating more foils than will be displayed.
! 9:
! 10: With a numerical response, it is necessary to create variables with random values.
! 11: This can be done with a Perl script. Such a script is created by inserting a
! 12: \texttt{script} element (in the \textit{Block} menu) and setting its
! 13: \texttt{type} attribute to '\texttt{loncapa/perl}'.
! 14:
! 15: Here is a little cookbook for randomizing values with a Perl script:
! 16: \begin{itemize}
! 17: \item To set variable a to the value 1:
! 18:
! 19: \texttt{\$a = 1;}
! 20:
! 21: \item To set variable a to the value 'text':
! 22:
! 23: \texttt{\$a = 'text';}
! 24:
! 25: Note that single quotes take the value literally, while double quotes replace variables by their values.
! 26:
! 27: \item To pick a random number between 1 and 5 (included), with a step of 0.5:
! 28:
! 29: \texttt{\$a = random(1, 5, 0.5);}
! 30:
! 31: (the step can be omitted to use a step of 1)
! 32:
! 33: \item To chose a value randomly in a list of text entries:
! 34:
! 35: \begin{verbatim}
! 36: @list = ('one', 'two', 'three');
! 37: $n = random(1, scalar(@list));
! 38: $a = choose($n, @list);\end{verbatim}
! 39:
! 40: \item Math operators:
! 41:
! 42: \texttt{+, -, *, /, **, \%}
! 43:
! 44: \item Math functions:
! 45:
! 46: \texttt{sin, cos, tan, asin, acos, atan, atan2, log, log10, exp, pow, sqrt, abs, sgn, erf, erfc, ceil, floor, min, max, factorial, sinh, cosh, tanh, asinh, acosh, atanh}
! 47:
! 48: \item Comments:
! 49:
! 50: \texttt{\# This is a comment.}
! 51: \end{itemize}
! 52:
! 53: Once created in a script, variables can be used anywhere afterwards, still prefixed with
! 54: \texttt{\$}. In particular, a numerical response answer can be set to a variable.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>