Using the very experimental l3rand
package (currently in the l3trial
directory of the LaTeX3 code repository, which means it is really not stable), you can do the following.
\documentclass{article}
\usepackage{l3rand,xparse}
\ExplSyntaxOn
\rand_seed_from_time:
\cs_generate_variant:Nn \tl_item:nn { nf }
\DeclareDocumentCommand {\random} {m}
{
\tl_item:nf {#1} { \rand_range:nn {0} { \tl_length:n {#1} - 1 } }
\rand_clean:
}
\ExplSyntaxOff
\begin{document}
\newcommand{\name}{Dave}
\random { {Dear \name,} {Hello \name,} {Greetings \name,} {Hi \name,} {To \name,} }
\random { {You are invited to} {You are welcome to} {I would like to invite you to} {This is an invitation to} {You may want to} }
attend...
\end{document}
Currently, \rand_range:nn {
<begin>
} {
<end>
}
produces a random number between <begin>
and <end>
inclusive, hence the need to subtract 1. This may very well be changed later. Also, \rand_seed_from_time:
might be renamed by the time this solution is used by anyone.
I added braces around the whole argument of \random
, otherwise TeX has no easy way of knowing where it ends.