[texhax] random order

Oleg Katsitadze olegkat at gmail.com
Fri Oct 13 13:04:00 CEST 2006

On Thu, Oct 12, 2006 at 01:30:12PM -0400, Tom Sgouros wrote:
> Can someone help me think of a way to get 11 items in a random order?

In plain TeX you can try the code below.  It will produce
identical results for different runs if those runs occur
within the same minute, because random.tex uses the seed
which changes only every minute -- that's what \time

\input random


% Define a new item.
  \advance\icount by1
  % Define a macro with the name `n' where n is the item's number.
  \expandafter\def \csname \number\icount \endcsname
% Printing of items.
\def\printitem#1{\csname \number#1\endcsname}
% Print all defined items in random order.
  % Unset all flags.
    \expandafter\let \csname flag\number\i \endcsname a%
    \advance\i by-1
    \ifnum\i > 0 \repeat
  % Print random items, each item once, until every item has been
  % printed.
    % Get random number \j.
    % Print item \j only if its flag is unset.
    \expandafter\ifx \csname flag\number\j \endcsname a%
      \expandafter\let \csname flag\number\j \endcsname b% Set the flag.
      \advance\i by-1
      \ifnum\i > 0 \printbetweenitems\fi
    \ifnum\i > 0 \repeat





More information about the texhax mailing list