There is no internal mechanism by which \pgfmathrandomitem
truly knows whether a list is empty. The case below shows this anomaly:
\documentclass{article}
\usepackage{pgf}
\makeatletter
\newcommand{\pgfmathclearrandomlist}[1]{%
\expandafter\global\expandafter\let\csname pgfmath@randomlist@#1\endcsname\relax}
\makeatother
\begin{document}
\pgfmathdeclarerandomlist{list}{{item1}{item2}{item3}{item4}}
\pgfmathrandomitem{\result}{list}\result% Returns item1/item2/item3/item4
\pgfmathdeclarerandomlist{list}{}
\pgfmathrandomitem{\result}{list}\result% Returns item1
\pgfmathdeclarerandomlist{list}{{}}
\pgfmathrandomitem{\result}{list}\result% Returns {}
\pgfmathclearrandomlist{list}
\pgfmathrandomitem{\result}{list}\result% List doesn't exist
\end{document}
The first instruction set creates a list with four items, from which a random one is selected. The second instruction "clears" this list, although the output is always the first item in the previously-defined list - item1
. You can visually clear the list by giving it a single item that is empty - {}
, but that may not help. Perhaps the solution would be to update the way \pgfmathdeclarerandomlist
works when being assigned an empty list (this would be a marginal update/patch, since it seems like a bug), or clear it officially using \pgfmathclearrandomlist
.
\pgfmathdeclarerandomlist{list}{{item3}{item4}...}
after some initial usage of the command, the contents in{list}
, i.e.{item1}{item2}...
, will simply get replaced by{item3}{item4}...