Debian Codegraph @

texmf-dist/doc/latex/randintlist/randintlist-doc.tex

raw
1 % !TeX TXS-program:compile = txs:///arara
2 % arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}
3 % arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}
4
5 \documentclass[11pt,a4paper]{ltxdoc}
6 \usepackage{bera}
7 \usepackage{inconsolata}
8 \usepackage[T1]{fontenc}
9 \usepackage[scale=0.875]{cabin}
10 \usepackage{randintlist}
11 \usepackage{fancyvrb}
12 \usepackage{fancyhdr}
13 \usepackage{tabularray}
14 \usepackage{fontawesome5}
15 \fancyhf{}
16 \renewcommand{\headrulewidth}{0pt}
17 \lfoot{\sffamily\small [randintlist]}
18 \cfoot{\sffamily\small - \thepage{} -}
19 \rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}}
20 \usepackage{hologo}
21 \providecommand\tikzlogo{Ti\textit{k}Z}
22 \providecommand\TeXLive{\TeX{}Live\xspace}
23 \let\TikZ\tikzlogo
24
25 \usepackage{hyperref}
26 \urlstyle{same}
27 \hypersetup{pdfborder=0 0 0}
28 \usepackage[margin=2cm]{geometry}
29 \setlength{\parindent}{0pt}
30 \def\TPversion{0.20a}
31 \def\TPdate{20/02/2026}
32 \usepackage{tcolorbox}
33 \usepackage{pgffor}
34 \tcbuselibrary{breakable,skins,hooks,listingsutf8}
35 %\usepackage{soul}
36 %\sethlcolor{lightgray!25}
37
38 \lstset{
39 language=[LaTeX]TeX,%
40 basicstyle=\ttfamily,%
41 keywordstyle={\color{blue}},%
42 classoffset=0,%
43 keywords={},%
44 alsoletter={-},%
45 keywordstyle={\color{blue}},%
46 classoffset=1,%
47 alsoletter={-},%
48 morekeywords={randintlist},%
49 keywordstyle={\color{violet}},%
50 classoffset=2,%
51 alsoletter={-},%
52 morekeywords={\randintlist,\getitemfromrandintlist},%
53 keywordstyle={\color{green!50!black}},%
54 classoffset=3,%
55 morekeywords={min,max,nb,seed,sort,sep,repeat,exclude},%
56 keywordstyle={\color{orange}}
57 }
58
59 \newtcblisting{DemoCode}[1]{%
60 enhanced,width=\linewidth,%
61 bicolor,size=title,%
62 colback=cyan!10!white,%
63 colbacklower=cyan!5!white,%
64 colframe=cyan!75!black,%
65 listing options={%
66 breaklines=true,%
67 breakatwhitespace=true,%
68 style=tcblatex,basicstyle=\small\ttfamily,%
69 tabsize=4,%
70 commentstyle={\itshape\color{gray}},
71 keywordstyle={\color{blue}},%
72 classoffset=0,%
73 keywords={\usepackage,\includegraphics,xstring,listofitems,tikz,calc,simplekv,graphicx,\readlist,\showitems,\xintFor,\xintSeq},%
74 alsoletter={-},%
75 keywordstyle={\color{blue}},%
76 classoffset=1,%
77 alsoletter={-},%
78 morekeywords={randintlist},%
79 keywordstyle={\color{violet}},%
80 classoffset=2,%
81 alsoletter={-},%
82 morekeywords={\randintlist,\getitemfromrandintlist,\ListeRandint,\ExtraireEltListeRandint},%
83 keywordstyle={\color{green!50!black}},%
84 classoffset=3,%
85 morekeywords={min,max,nb,seed,sort,sep,repeat,Min,Max,Nb,Graine,Sep,Tri,Repet,exclude,Exclure},%
86 keywordstyle={\color{orange}}
87 },%
88 #1
89 }
90
91 \newtcbinputlisting\DemoCodeFile[1]{%
92 enhanced,width=\linewidth,%
93 bicolor,size=title,%
94 colback=lightgray!10!white,%
95 colbacklower=lightgray!5!white,%
96 colframe=lightgray!75!black,%
97 listing options={%
98 breaklines=true,%
99 breakatwhitespace=true,%
100 style=tcblatex,
101 basicstyle=\scriptsize\ttfamily,%
102 tabsize=4,%
103 commentstyle={\itshape\color{gray}},%
104 lastline=246
105 },%
106 breakable,
107 listing only,%
108 listing file={#1}
109 }
110
111 \NewDocumentCommand\ShowCode{ m }{%
112 \lstinline{#1}%
113 }
114
115 \begin{document}
116
117 \thispagestyle{empty}
118
119 \begin{center}
120 \begin{minipage}{0.88\linewidth}
121 \begin{tcolorbox}[colframe=yellow,colback=yellow!15]
122 \begin{center}
123 \renewcommand{\arraystretch}{1.25}%
124 \begin{tabular}{c}
125 {\Huge \texttt{randintlist}}\\
126 \\
127 {\LARGE Creating random integer number lists,} \\
128 {\LARGE with multiple numbers or not,} \\
129 {\LARGE sorted or not.} \\
130 \\
131 {\small \texttt{Version \TPversion{} -- \TPdate}}
132 \end{tabular}
133 \end{center}
134 \end{tcolorbox}
135 \end{minipage}
136 \end{center}
137
138 \begin{center}
139 \begin{tabular}{c}
140 \texttt{Cédric Pierquet}\\
141 {\ttfamily c pierquet -- at -- outlook . fr}\\
142 \texttt{\url{https://github.com/cpierquet/latex-packages/tree/main/randintlist}} \\
143 \end{tabular}
144 \end{center}
145
146 \hrule
147
148 \vfill
149
150 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
151 10 numbers, between 1 and 100, without repetition:
152
153 \hfill\randintlist[min=1,max=100,nb=10]{\mylist}\textcolor{red}{\mylist}\hfill~
154
155 The 5th value is:
156
157 \hfill\textcolor{blue}{\getitemfromrandintlist{\mylist}{5}}\hfill~
158 \end{tcolorbox}
159
160 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
161 10 numbers, between 1 and 100, without multiples of 5:
162
163 \hfill\randintlist[min=1,max=100,nb=10,exclude={5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100}]{\mylist}\textcolor{olive}{\mylist}\hfill~
164
165 The 9th value is:
166
167 \hfill\textcolor{purple}{\getitemfromrandintlist{\mylist}{9}}\hfill~
168 \end{tcolorbox}
169
170 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
171 15 numbers, between 1 and 20, with repetition:
172
173 \hfill\randintlist[min=1,max=20,nb=15,repeat]{\mylist}\textcolor{red}{\mylist}\hfill~
174
175 The last value is:
176
177 \hfill\textcolor{blue}{\getitemfromrandintlist{\mylist}{-1}}\hfill~
178 \end{tcolorbox}
179
180 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
181 6 sorted numbers, between 1 and 51, without repetition:
182
183 \hfill\randintlist[min=1,max=51,nb=6,sort=asc]{\mylist}ascending : \textcolor{red}{\mylist}\hfill~
184
185 \hfill\randintlist[min=1,max=51,nb=6,sort=des,sep=>]{\mylist}descending : \textcolor{red}{\mylist}\hfill~
186 \end{tcolorbox}
187
188 \vfill~
189
190 \hrule
191
192 \medskip
193
194 \emph{%
195 1. The \textsf{luarandom} package do the same things, but with the obligation to compile with \hologo{LuaLaTeX}.
196 }
197
198 \emph{%
199 2. The \textsf{tuple} package is so much better\ldots\ but I keep \texttt{randintlist}, without new features\ldots
200 }
201
202 \medskip
203
204 \hrule
205
206 \vspace*{5mm}
207
208 \pagebreak
209
210 \phantomsection
211
212 \hypertarget{matoc}{}
213
214 \tableofcontents
215
216 \vspace*{5mm}
217
218 %\hrule
219
220 \pagebreak
221
222 \section{Loading, useful packages}
223
224 In order to load \texttt{randintlist}, simply use:
225
226 \begin{DemoCode}{listing only}
227 \usepackage{randintlist}
228 \end{DemoCode}
229
230 Loaded packages are \texttt{ifthen}, \texttt{simplekv}, \texttt{listofitems}, \texttt{randomlist}, \texttt{xintexpr} and \texttt{xstring}.
231
232 \section{The Macros}
233
234 \subsection{Global usage}
235
236 Package \texttt{randintlist} supports the creation of random integer number lists where a number will appear only once or multiple times. Generated lists can te used with \texttt{listofitems}.
237
238 \hfill\textbf{All engines \TeX\ are compatible with this package.}\hfill~
239
240 \subsection{Generate the list}
241
242 \begin{DemoCode}{listing only}
243 %generate list
244 \randintlist[keys]{\macro}
245 \end{DemoCode}
246
247 Available keys are:
248
249 \begin{itemize}
250 \item \ShowCode{min}: minimum value (default \ShowCode{1});
251 \item \ShowCode{max}: maximum value (default \ShowCode{50});
252 \item \ShowCode{nb}: number of values (default \ShowCode{6});
253 \item \ShowCode{sep}: separator for the list (default \ShowCode{,});
254 \item \ShowCode{sort}: sorting options, within \ShowCode{no/asc/dec} (default \ShowCode{no});
255 \item \ShowCode{repeat}: boolean to authorize repeating values (default \ShowCode{false});
256 \item \ShowCode{exclude}: list of excluded values (default \ShowCode{empty});
257 \item \ShowCode{seed}: random seed value according to used packages (default \ShowCode{-}).
258 \end{itemize}
259
260 \begin{DemoCode}{}
261 %default values
262 \randintlist{\mylistA}\mylistA
263 \end{DemoCode}
264
265 \begin{DemoCode}{}
266 %10 between 1 and 50, with ascending
267 \randintlist[sort=asc,min=1,max=50,nb=10]{\mylistB}\mylistB
268 \end{DemoCode}
269
270 \begin{DemoCode}{}
271 %15 between 1 and 50, with ascending and repetitions allowed
272 \randintlist[sort=asc,min=1,max=50,nb=15,repeat]{\mylistC}\mylistC
273 \end{DemoCode}
274
275 \begin{DemoCode}{}
276 %15 between 1 and 50, without multiples of 5
277 \randintlist[%
278 sort=asc,min=1,max=50,nb=15,repeat,%
279 exclude={5,10,15,20,25,30,35,40,45,50}]%
280 {\mylistC}\mylistC
281 \end{DemoCode}
282
283 \begin{DemoCode}{}
284 %list used with listofitems
285 \randintlist{\mylistD}\mylistD\par
286 \readlist*\mylistused{\mylistD}\showitems{\mylistused}\par
287 \mylistused[1]; \mylistused[-1]
288 \end{DemoCode}
289
290 \subsection{Accessing elements}
291
292 \begin{DemoCode}{listing only}
293 %accessing item
294 \getitemfromrandintlist[separator]{\macro}{index}[\macrores]
295 \end{DemoCode}
296
297 \begin{DemoCode}{}
298 %with default keys
299 \randintlist{\mylistE}raw list: \mylistE\par
300 items list:\par
301 \xintFor* #1 in {\xintSeq{1}{6}}\do{\getitemfromrandintlist{\mylistE}{#1}\par}
302 first element: \getitemfromrandintlist{\mylistE}{1}\par
303 \end{DemoCode}
304
305 \begin{DemoCode}{}
306 \getitemfromrandintlist{\mylistE}{3}[\myres]%
307 third element: \myres
308 \end{DemoCode}
309
310 \pagebreak
311
312 \subsection{Version française}
313
314 Voilà les commandes en version française, la syntaxe et les clés ne seront pas explicitées.
315
316 \begin{DemoCode}{listing only}
317 %obtenir la liste
318 \ListeRandint[Min=..,Max=..,Nb=..,Repet=..,Graine=..,Tri=..,Sep=..,Exclure=..]{\macro}
319
320 %extraire un élément
321 \ExtraireEltListeRandint[sep]{\macro}{position}[\macrores]
322 \end{DemoCode}
323
324 \begin{DemoCode}{}
325 %liste
326 \ListeRandint[Min=5,Max=15,Nb=7,Repet,Tri=croiss,Sep={/}]{\maliste}\maliste\\
327 %élément
328 \ExtraireEltListeRandint[/]{\maliste}{4}
329 \end{DemoCode}
330
331 \begin{DemoCode}{}
332 %liste
333 \ListeRandint[Min=50,Max=100,Nb=10,Repet,Tri=croiss]{\malisteB}\malisteB\\
334 %troisième élément
335 \ExtraireEltListeRandint{\malisteB}{3}[\montroisieme]%
336 troisième élément : \montroisieme
337 \end{DemoCode}
338
339 \pagebreak
340
341 \section{Example}
342
343 The following example uses \TikZ, and comes from \texttt{luarandom}'s documentation.
344
345 \begin{DemoCode}{}
346 \begin{tikzpicture}[scale=0.75]
347 \randintlist[min=1,max=100,nb=100]{\mylistsquare}
348 \draw[thin,gray] (0,0) grid (10,10) ;
349 \foreach \i in {1,...,100}{%
350 \xdef\tmpnumber{\getitemfromrandintlist{\mylistsquare}{\i}}%
351 \xdef\tmpnumberrow{\xinteval{\xintiiRem{\i-1}{10}}}%
352 \xdef\tmpnumbercol{\xinteval{\xintiiQuo{\i-1}{10}}}%
353 \draw ({0.5+\tmpnumbercol},{0.5+\tmpnumberrow}) node {\tmpnumber} ;
354 }%
355 \end{tikzpicture}
356 \end{DemoCode}
357
358 \pagebreak
359
360 \section{History}
361
362 \texttt{0.20a: Improvements in \hologo{LaTeX3} version of the package}
363
364 \texttt{0.1.6: Improvements in \hologo{LaTeX3} version of the package}
365
366 \texttt{0.1.5: \hologo{LaTeX3} version of the package}
367
368 \texttt{0.1.4: Bugfix}
369
370 \texttt{0.1.3: Bugfix}
371
372 \texttt{0.1.2: Changing name of internal macro}
373
374 \texttt{0.1.1: Possibility to exclude values}
375
376 \texttt{0.1.0: Initial version}
377
378 \section{The code}
379
380 \DemoCodeFile{randintlist.sty}
381
382 \end{document}