| 1 |
%% $Id: luarandom-doc.tex 813 2023-11-13 19:33:29Z herbert $ |
| 2 |
\documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false, |
| 3 |
headings=small, headinclude=false,footinclude=false,oneside,abstract=on]{pst-doc} |
| 4 |
|
| 5 |
\usepackage{xcolor,pstricks,multido} |
| 6 |
|
| 7 |
\usepackage{luarandom} |
| 8 |
\let\pstMathFV\fileversion |
| 9 |
\lstset{pos=t,wide=true,language=[LaTeX]{TeX},basicstyle=\footnotesize\ttfamily} |
| 10 |
% |
| 11 |
\makeatletter |
| 12 |
\def\DefOfOperator{\@ifstar{\DefOfOperator@}{\DefOfOperator@@}} |
| 13 |
\def\DefOfOperator@#1#2#3#4{{\operator@font#1}:\left\{\begin{array}{ccc} #2&\to\\ |
| 14 |
x&\mapsto\end{array}\right.} |
| 15 |
\def\DefOfOperator@@#1#2#3{{\operator@font#1}:\left\{\begin{array}{ccc} #2&\to\\ |
| 16 |
x&\mapsto&{\operator@font#1}(x)\end{array}\right.} |
| 17 |
\makeatother |
| 18 |
|
| 19 |
|
| 20 |
\begin{document} |
| 21 |
|
| 22 |
\title{\texttt{luarandom}} |
| 23 |
\subtitle{Create a list of random numbers with or without multiple values; v. 0.02} |
| 24 |
\author{Herbert Vo\ss} |
| 25 |
\docauthor{Herbert Vo\ss} |
| 26 |
\date{\today} |
| 27 |
\maketitle |
| 28 |
|
| 29 |
\tableofcontents |
| 30 |
|
| 31 |
|
| 32 |
\section{Random numbers} |
| 33 |
Package \LPack{luarandom} supports the creation of random number lists where a number will |
| 34 |
appear only once or multiple times. With Lua\TeX\ all random numbers are build with the help of Lua which |
| 35 |
has the advantage that there will be no problem with \TeX's limited parameter stack size. |
| 36 |
However, this package will \emph{not} run with other \TeX-engines than Lua\LaTeX. |
| 37 |
|
| 38 |
|
| 39 |
\section{The Macros} |
| 40 |
\begin{BDef} |
| 41 |
\Lcs{makeSimpleRandomNumberList}\OptArg{Seed}\Largb{Left}\Largb{Right}\Largb{N}\% multiple values possible\\ |
| 42 |
\Lcs{makeRandomNumberList}\OptArg{Seed}\Largb{Left}\Largb{Right}\Largb{N} \% no multiple values!\\ |
| 43 |
\Lcs{getNumberFromList}\Largb{number} |
| 44 |
\end{BDef} |
| 45 |
|
| 46 |
|
| 47 |
The list of the random numbers is saved in the Lua table \texttt{RandomNumbers}. |
| 48 |
|
| 49 |
|
| 50 |
\section{Examples} |
| 51 |
|
| 52 |
|
| 53 |
\begin{LTXexample}[pos=t] |
| 54 |
\small |
| 55 |
\makeSimpleRandomNumberList{1}{30}{30}% with multiple values (hopefully ;-) |
| 56 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 57 |
|
| 58 |
\makeRandomNumberList{1}{30}{30}% without multiple values |
| 59 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 60 |
\end{LTXexample} |
| 61 |
|
| 62 |
|
| 63 |
With the optional argument \verb|[seed number]|, the seed function is not called |
| 64 |
with the current time, but with the optional value (integer). |
| 65 |
|
| 66 |
\begin{LTXexample}[pos=t] |
| 67 |
\small |
| 68 |
\makeSimpleRandomNumberList[999]{1}{30}{30}% with multiple values and value seed |
| 69 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 70 |
|
| 71 |
\makeRandomNumberList[999]{1}{30}{30}% without multiple values and value seed |
| 72 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 73 |
|
| 74 |
\makeSimpleRandomNumberList[999]{1}{30}{30}% with multiple values and value seed |
| 75 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 76 |
|
| 77 |
\makeRandomNumberList{1}{30}{30}% without multiple values and time seed |
| 78 |
\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } |
| 79 |
\end{LTXexample} |
| 80 |
|
| 81 |
|
| 82 |
\begin{LTXexample}[pos=t] |
| 83 |
\makeRandomNumberList{2}{30}{5}% |
| 84 |
\multido{\iA=1+1}{5}{\getNumberFromList{\iA}, } |
| 85 |
\end{LTXexample} |
| 86 |
|
| 87 |
|
| 88 |
The following example uses PSTricks related packages which can be run directly |
| 89 |
with Lua\LaTeX. |
| 90 |
|
| 91 |
|
| 92 |
\begin{LTXexample}[pos=t] |
| 93 |
\newcounter{RandNo}\setcounter{RandNo}{1} |
| 94 |
\def\n{10} \def\N{\the\numexpr\n*\n} |
| 95 |
\makeRandomNumberList{1}{\N}{\N} |
| 96 |
\begin{pspicture}(\n,\n) |
| 97 |
\psgrid[subgriddiv=0,gridlabels=0pt] |
| 98 |
\multido{\rRow=0.5+1.0}{\n}{\multido{\rCol=0.5+1.0}{\n}{% |
| 99 |
\rput(\rCol,\rRow){\textcolor{randomhsb}{\getNumberFromList{\theRandNo}}}% |
| 100 |
\stepcounter{RandNo}}} |
| 101 |
\end{pspicture} |
| 102 |
\end{LTXexample} |
| 103 |
|
| 104 |
\section{The code} |
| 105 |
|
| 106 |
\lstinputlisting{luarandom.sty} |
| 107 |
|
| 108 |
\printindex |
| 109 |
|
| 110 |
|
| 111 |
\end{document} |