Is there a simple way to generate a unique identifier like random uuids in XeLaTeX with a package or a simple LaTeX script which does not need any external commands to execute?
Asked
Active
Viewed 405 times
0
-
Welcome to TeX.SE! Maybe this can help you: http://tex.stackexchange.com/q/332329/101651 – CarLaTeX Jan 29 '17 at 16:59
1 Answers
2
Since XeTeX currently has no native random number support, we need random.tex; also binhex.tex helps.
\documentclass{article}
\input{random}
\input{binhex}
\makeatletter
\newcount\temp@uuid
\newcommand{\makeUUID}[1]{%
\@ifdefinable{#1}{\make@UUID{#1}}%
}
\newcommand{\make@UUID}[1]{%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{\nhex{4}{\temp@uuid}}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}-}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}-}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}-}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}-}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}}%
\setrannum{\temp@uuid}{0}{"10000}%
\edef#1{#1\nhex{4}{\temp@uuid}}%
% remove the following three lines if you're happy with uppercase hex digits
\lowercase\expandafter{%
\expandafter\def\expandafter#1\expandafter{#1}%
}%
}
\makeatother
\makeUUID\foo
\makeUUID\baz
\begin{document}
\ttfamily
\foo
\baz
\end{document}
egreg
- 1,121,712
