[Tex/LaTex] Generate random numbers with a specific font

fontsrandom numberstables

My objective is to create a table or some form of environment as shown in the figure below.

What I want

The numbers should be randomly generated every time you compile and have the font shown below.

Number with specific font

Is this possible?

Best Answer

You could use TikZ nodes and pgf made random numbers, for example:

\documentclass{article}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[ocr-a]{ocr}
\usetikzlibrary{chains,positioning}
\usepackage{datetime}
\pgfmathparse{\year+\time+\currenthour+\currentminute*\currentsecond}
\pgfmathsetseed{\pgfmathresult}
\begin{document}
\begin{tikzpicture}[start chain=1 going right,node distance=-0.4pt]
    \foreach \x in {1,2,...,15} {
        \node (\x) [draw,on chain=1] {\pgfmathparse{random(0,9)}\ocr{\pgfmathresult}};} 
    \node [above of=1,anchor=south west,yshift=2ex,xshift=-2.4ex]
        {Do not write in this area};
    \node [below of=1,anchor=north west,yshift=-2ex,xshift=-2.4ex]
        {\scshape Each document must have a unique serial number};
\end{tikzpicture}
\end{document}

The output, using ocr-a numbers, as Mico advised in his comment below:

random numbers on chain

To get different numbers for each compilation, you could initialize the random number generator yourself by

\pgfmathsetseed{<integer>}

By default, it's the value of \time*\year. So it would't change during each compilation, so I used the datetime package to use also minutes and seconds for calculating the seed. So the random values should change each second. You could also use values or counters in your .aux file instead.

You can get the ocr-a font from CTAN: http://ctan.org/pkg/ocr-a. If you don't manage to install it, a quick workaround: you could load the mf and tfm files (for example from here), put them into your document directory and run (with fontenc and ocr as above) - it worked for me.

Related Question