texlive[72383] Master/texmf-dist: randintlist (25sep24)

commits+karl at tug.org commits+karl at tug.org
Wed Sep 25 21:27:52 CEST 2024


Revision: 72383
          https://tug.org/svn/texlive?view=revision&revision=72383
Author:   karl
Date:     2024-09-25 21:27:52 +0200 (Wed, 25 Sep 2024)
Log Message:
-----------
randintlist (25sep24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.pdf
    trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.tex
    trunk/Master/texmf-dist/tex/latex/randintlist/randintlist.sty

Modified: trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.tex	2024-09-25 19:27:43 UTC (rev 72382)
+++ trunk/Master/texmf-dist/doc/latex/randintlist/randintlist-doc.tex	2024-09-25 19:27:52 UTC (rev 72383)
@@ -27,8 +27,8 @@
 \hypersetup{pdfborder=0 0 0}
 \usepackage[margin=2cm]{geometry}
 \setlength{\parindent}{0pt}
-\def\TPversion{0.1.0}
-\def\TPdate{23/09/2024}
+\def\TPversion{0.1.1}
+\def\TPdate{24/09/2024}
 \usepackage{tcolorbox}
 \usepackage{pgffor}
 \tcbuselibrary{breakable,skins,hooks,listingsutf8}
@@ -52,7 +52,7 @@
 	morekeywords={\randintlist,\getitemfromrandintlist},%
 	keywordstyle={\color{green!50!black}},%
 	classoffset=3,%
-	morekeywords={min,max,nb,seed,sort,sep,repeat},%
+	morekeywords={min,max,nb,seed,sort,sep,repeat,exclude},%
 	keywordstyle={\color{orange}}
 }
 
@@ -82,7 +82,7 @@
 		morekeywords={\randintlist,\getitemfromrandintlist,\ListeRandint,\ExtraireEltListeRandint},%
 		keywordstyle={\color{green!50!black}},%
 		classoffset=3,%
-		morekeywords={min,max,nb,seed,sort,sep,repeat,Min,Max,Nb,Graine,Sep,Tri,Repet},%
+		morekeywords={min,max,nb,seed,sort,sep,repeat,Min,Max,Nb,Graine,Sep,Tri,Repet,exclude,Exclure},%
 		keywordstyle={\color{orange}}
 	},%
 	#1
@@ -101,7 +101,7 @@
 		basicstyle=\scriptsize\ttfamily,%
 		tabsize=4,%
 		commentstyle={\itshape\color{gray}},%
-		lastline=113
+		lastline=148
 	},%
 	breakable,
 	listing only,%
@@ -158,6 +158,16 @@
 \end{tcolorbox}
 
 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
+10 numbers, between 1 and 100, without multiples of 5 :
+
+\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~
+
+The 9th value is :
+
+\hfill\textcolor{purple}{\getitemfromrandintlist{\mylist}{9}}\hfill~
+\end{tcolorbox}
+
+\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
 15 numbers, between 1 and 20, with repetition :
 
 \hfill\randintlist[min=1,max=20,nb=15,repeat]{\mylist}\textcolor{red}{\mylist}\hfill~
@@ -213,7 +223,7 @@
 \usepackage{randintlist}
 \end{DemoCode}
 
-Loaded packages are \texttt{simplekv}, \texttt{listofitems}, \texttt{randomlist},  \texttt{xintexpr} and \texttt{xstring}
+Loaded packages are \texttt{ifthen}, \texttt{simplekv}, \texttt{listofitems}, \texttt{randomlist},  \texttt{xintexpr} and \texttt{xstring}
 
 \section{The Macros}
 
@@ -239,6 +249,7 @@
 	\item \ShowCode{sep} : separator for the list (default \ShowCode{,}) ;
 	\item \ShowCode{sort} : sorting options, within \ShowCode{no/asc/dec} (default \ShowCode{no}) ;
 	\item \ShowCode{repeat} : boolean to authorize repeating values (default \ShowCode{false}) ;
+	\item \ShowCode{exclude} : list of excluded values (default \ShowCode{empty}) ;
 	\item \ShowCode{seed} : random seed value according to used packages (default \ShowCode{-}).
 \end{itemize}
 
@@ -258,6 +269,14 @@
 \end{DemoCode}
 
 \begin{DemoCode}{}
+%15 between 1 and 50, without multiples of 5
+\randintlist[%
+	sort=asc,min=1,max=50,nb=15,repeat,%
+	exclude={5,10,15,20,25,30,35,40,45,50}]%
+	{\mylistC}\mylistC
+\end{DemoCode}
+
+\begin{DemoCode}{}
 %list used with listofitems
 \randintlist{\mylistD}\mylistD\par
 \readlist*\mylistused{\mylistD}\showitems{\mylistused}\par
@@ -276,7 +295,7 @@
 \randintlist{\mylistE}raw list : \mylistE\par
 items list :\par
 \xintFor* #1 in {\xintSeq{1}{6}}\do{\getitemfromrandintlist{\mylistE}{#1}\par}
-\getitemfromrandintlist{\mylistE}{1}
+first element : \getitemfromrandintlist{\mylistE}{1}
 \end{DemoCode}
 
 \subsection{Version française}
@@ -285,7 +304,7 @@
 
 \begin{DemoCode}{listing only}
 %obtenir la liste
-\ListeRandint[Min=...,Max=...,Nb=...,Repet=...,Graine=...,Tri=...,Sep=...]{\macro}
+\ListeRandint[Min=..,Max=..,Nb=..,Repet=..,Graine=..,Tri=..,Sep=..,Exclure=..]{\macro}
 
 %extraire un élément
 \ExtraireEltListeRandint[sep]{\macro}{position}
@@ -293,8 +312,7 @@
 
 \begin{DemoCode}{}
 %liste
-\ListeRandint[Min=5,Max=15,Nb=7,Repet,Tri=croiss,Sep={/}]{\maliste}\maliste
-
+\ListeRandint[Min=5,Max=15,Nb=7,Repet,Tri=croiss,Sep={/}]{\maliste}\maliste\\
 %élément
 \ExtraireEltListeRandint[/]{\maliste}{4}
 \end{DemoCode}
@@ -322,6 +340,8 @@
 
 \section{History}
 
+\texttt{0.1.1 : Possibility to exclude values}
+
 \texttt{0.1.0 : Initial version}
 
 \section{The code}

Modified: trunk/Master/texmf-dist/tex/latex/randintlist/randintlist.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/randintlist/randintlist.sty	2024-09-25 19:27:43 UTC (rev 72382)
+++ trunk/Master/texmf-dist/tex/latex/randintlist/randintlist.sty	2024-09-25 19:27:52 UTC (rev 72383)
@@ -2,9 +2,10 @@
 % licence    : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{randintlist}[2024/09/23 0.1.0 Create a list of random numbers with or without multiple values]
+\ProvidesPackage{randintlist}[2024/09/24 0.1.1 Create a list of random numbers with or without multiple values]
 
 %------History
+% 0.1.1	Possibility to exclude values
 % 0.1.0	Initial version
 
 %------Packages
@@ -13,8 +14,9 @@
 \RequirePackage{randomlist}
 \RequirePackage{xintexpr}
 \RequirePackage{xstring}
+\RequirePackage{ifthen}
 
-%-----Macros for sorting and seed
+%-----Macros (latex3) for sorting and seed
 \ExplSyntaxOn
 \cs_new_eq:NN \randintseed \sys_gset_rand_seed:n
 \NewDocumentCommand\intascsortlist{m}
@@ -37,6 +39,16 @@
 }
 \ExplSyntaxOff
 
+%----Internal macro (latex2) for testing if element is in list
+\newcommand\ifintvalueinlist[2]{\IfSubStr{,#2,}{,#1,}}
+
+\newcommand\boolvalueinlist[2]{\IfSubStr{,#2,}{,#1,}{\def\resisinlist{1}}{\def\resisinlist{0}}}
+
+\newcommand\xintifintvalueinlist[4]{%
+	\IfSubStr{,#2,}{,#1,}{\xdef\RESTMPVALUE{1}}{\xdef\RESTMPVALUE{0}}%
+	\xintifboolexpr{ \RESTMPVALUE == 1}{#3}{#4}%
+}
+
 %----Macro for generating
 \defKV[randomlistintegers]{%
 	min=\def\TAEEmin{#1},%
@@ -44,7 +56,8 @@
 	nb=\def\TAEEnb{#1},%
 	sep=\def\TAEEsep{#1},%
 	sort=\def\TAEEtri{#1},%
-	seed=\def\TAEEseed{#1}
+	seed=\def\TAEEseed{#1},%
+	exclude=\def\TAEEexcluded{#1}
 }
 
 \setKVdefault[randomlistintegers]{%
@@ -54,7 +67,8 @@
 	sep={,},%
 	sort=no,%
 	repeat=false,%
-	seed={-}
+	seed={-},%
+	exclude={}
 }
 
 \NewList{tmprandintlist}
@@ -69,10 +83,23 @@
 				{%
 					\randintseed{\TAEEseed}%
 				}%
-			%list creation (first then other)
-			\xdef#2{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+			%list creation of first element
+			\def\resisinlist{1}%
+			\whiledo{\resisinlist=1}{%
+				\xdef\tmpresrandint{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+				\boolvalueinlist{\tmpresrandint}{\TAEEexcluded}%
+			}%
+			\xdef#2{\tmpresrandint}%
+			%list creation of other elements
 			\xintFor* ##1 in {\xintSeq{2}{\TAEEnb}}%
-				\do{\xdef#2{#2,\fpeval{randint(\TAEEmin,\TAEEmax)}}}%
+				\do{%
+					\def\resisinlist{1}%
+					\whiledo{\resisinlist=1}{%
+						\xdef\tmpresrandint{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+						\boolvalueinlist{\tmpresrandint}{\TAEEexcluded}%
+					}%
+				\xdef#2{#2,\tmpresrandint}%
+				}%
 		}%
 		{%no repeating
 			%randomize numbers
@@ -83,11 +110,19 @@
 				}%
 			\ClearList{tmprandintlist}%clearing the list
 			\xintFor* ##1 in {\xintSeq{\TAEEmin}{\TAEEmax}}%
-				\do{\InsertRandomItem{tmprandintlist}{##1}}%
+				\do{%
+					\ifintvalueinlist{##1}{\TAEEexcluded}%
+						{}%
+						{%
+							\InsertRandomItem{tmprandintlist}{##1}%
+						}%
+				}%
 			%list creation (first then other)
 			\xdef#2{\tmprandintlist[0]}%
 			\xintFor* ##1 in {\xintSeq{1}{\TAEEnb-1}}%
-				\do{\xdef#2{#2,\tmprandintlist[##1]}}%
+				\do{%
+					\xdef#2{#2,\tmprandintlist[##1]}%
+				}%
 		}%
 	%sorting
 	\IfStrEq{\TAEEtri}{asc}%if ascending
@@ -119,7 +154,8 @@
 	Nb=\def\TAEEnb{#1},%
 	Sep=\def\TAEEsep{#1},%
 	Tri=\def\TAEEtri{#1},%
-	Graine=\def\TAEEseed{#1}
+	Graine=\def\TAEEseed{#1},%
+	Exclure=\def\TAEEexcluded{#1}
 }
 
 \setKVdefault[randomlisteentiers]{%
@@ -129,7 +165,8 @@
 	Sep={,},%
 	Tri=non,%
 	Repet=false,%
-	Graine={-}
+	Graine={-},%
+	Exclure={}
 }
 
 \NewDocumentCommand\ListeRandint{ O{} m }{%1=keys,2=listname
@@ -142,10 +179,23 @@
 				{%
 					\randintseed{\TAEEseed}%
 				}%
-			%list creation (first then other)
-			\xdef#2{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+			%list creation of first element
+			\def\resisinlist{1}%
+			\whiledo{\resisinlist=1}{%
+				\xdef\tmpresrandint{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+				\boolvalueinlist{\tmpresrandint}{\TAEEexcluded}%
+			}%
+			\xdef#2{\tmpresrandint}%
+			%list creation of other elements
 			\xintFor* ##1 in {\xintSeq{2}{\TAEEnb}}%
-				\do{\xdef#2{#2,\fpeval{randint(\TAEEmin,\TAEEmax)}}}%
+				\do{%
+					\def\resisinlist{1}%
+					\whiledo{\resisinlist=1}{%
+						\xdef\tmpresrandint{\fpeval{randint(\TAEEmin,\TAEEmax)}}%
+						\boolvalueinlist{\tmpresrandint}{\TAEEexcluded}%
+					}%
+				\xdef#2{#2,\tmpresrandint}%
+				}%
 		}%
 		{%no repeating
 			%randomize numbers
@@ -156,11 +206,19 @@
 				}%
 			\ClearList{tmprandintlist}%clearing the list
 			\xintFor* ##1 in {\xintSeq{\TAEEmin}{\TAEEmax}}%
-				\do{\InsertRandomItem{tmprandintlist}{##1}}%
+				\do{%
+					\ifintvalueinlist{##1}{\TAEEexcluded}%
+						{}%
+						{%
+							\InsertRandomItem{tmprandintlist}{##1}%
+						}%
+				}%
 			%list creation (first then other)
 			\xdef#2{\tmprandintlist[0]}%
 			\xintFor* ##1 in {\xintSeq{1}{\TAEEnb-1}}%
-				\do{\xdef#2{#2,\tmprandintlist[##1]}}%
+				\do{%
+					\xdef#2{#2,\tmprandintlist[##1]}%
+				}%
 		}%
 	%sorting
 	\IfStrEq{\TAEEtri}{croiss}%if ascending



More information about the tex-live-commits mailing list.