10

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}
ocalex86
  • 205
  • 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

1 Answers1

18

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.

egreg
  • 1,121,712