# Have a new seed in pgfmath more often

I'm using pgfmath in my code since I need some randomness and I want the seed used for the randomness to be updated each time I compile. I read that pgfmath is updating the seed every minute, which is not enough for what I'm doing. Is there a way to force him to update every second or, even better, every millisecond?

Here is a toy example of code which prints randomly 4 elements in the list {one, two, three, four}

\documentclass[11pt,a4paper]{report}
\usepackage{tikz}
\begin{document}
\pgfmathdeclarerandomlist{mylist}{{one}{two}{three}{four}}
\pgfmathrandomitem\elem{mylist}\elem\
\pgfmathrandomitem\elem{mylist}\elem\
\pgfmathrandomitem\elem{mylist}\elem\
\pgfmathrandomitem\elem{mylist}\elem
\end{document}

• Can you add a simple code example to play with? If you use pdflatex then maybe \pgfmathsetseed{\pdfrandomseed} might do. – egreg Nov 12 '13 at 15:29
• I added a toy example. I' compiling with latex and not with pdflatex and I would prefer continuing so. – ocalex86 Nov 12 '13 at 15:36

If you use pdflatex or LuaLaTeX, then

\documentclass{article}
\usepackage{pgf}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{document}

\pgfmathsetmacro{\test}{rand}\test

\end{document}


will pick a random seed each time. With XeLaTeX there's nothing similar. The value of \pdfrandomseed doesn't change during a run, though.

• Thanks, but as said above, I would prefer to use LaTeX if possible. If not, I will have to adapt and use pdfLaTeX – ocalex86 Nov 12 '13 at 15:39
• @ocalex86 You are using pdflatex also when running latex for DVI output. – egreg Nov 12 '13 at 15:40
• Oh, sorry, then. I just tried, it works well. Thanks a lot ! – ocalex86 Nov 12 '13 at 15:42
• For LuaLaTeX this (now) requires just \randomseed instead of \pdfrandomseed. – Alan Munn Jul 2 '17 at 17:38