0

This question already has an answer here:

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?

marked as duplicate by Werner, Stefan Pinnow, Maarten Dhondt, Mico, Andrew Swann Jan 30 '17 at 8:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jan 29 '17 at 16:47

This question came from our site for professional and enthusiast programmers.

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}

enter image description here