[Tex/LaTex] Random Page Numbers

page-numberingrandom numbers

I need some help with a crazy idea. For a book I want the page numbers to be a random permutation. As an example, if the book would have 5 pages, I want something like (4,1,2,5,3). Optimally, the table of contents and references would work. I don't know enough about TeX to do it myself. I am already happy about some directions in how to proceed.

I use the book LaTeX class and XeLatex.

Thank you!

Best Answer

This uses the specified permutation within range, if you have more pages than that it reverts to normal, so you can always modify the definition at the end once you know how many pages you have

enter image description here

\documentclass{book}

\renewcommand\thepage{%
\ifcase\value{page}%
0\or
4\or
1\or
2\or
5\or
6\or
3\else
\arabic{page}%
\fi}

\begin{document}

\tableofcontents

\chapter{Intro}
\section{Zzzz}aaaa
\section{Zzzzz}aaaa \clearpage bbbb
\section{Zzzzz}aaaa


\chapter{Something}
\section{Zzzz zzz}aaaa
\section{Zzzzzz zzz}aaaa \clearpage bbbb
\section{Zzzzzzz zzz}aaaa


\end{document}