# Generating random uuid in xelatex [duplicate]

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?

## migrated from stackoverflow.comJan 29 '17 at 16:47

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

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}