From e20928a0f9f4a7faa8bb21915e761e11e34f04ff Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 14 Nov 2023 03:01:05 +0000 Subject: CTAN sync 202311140301 --- macros/luatex/latex/luarandom/Changes | 2 ++ macros/luatex/latex/luarandom/README | 2 +- .../luatex/latex/luarandom/doc/luarandom-doc.pdf | Bin 49787 -> 70042 bytes .../luatex/latex/luarandom/doc/luarandom-doc.tex | 39 ++++++++++++++++----- macros/luatex/latex/luarandom/latex/luarandom.sty | 37 +++++++++++-------- 5 files changed, 56 insertions(+), 24 deletions(-) (limited to 'macros/luatex/latex') diff --git a/macros/luatex/latex/luarandom/Changes b/macros/luatex/latex/luarandom/Changes index 29cf20e023..ac867c2130 100644 --- a/macros/luatex/latex/luarandom/Changes +++ b/macros/luatex/latex/luarandom/Changes @@ -1,4 +1,6 @@ ..... luarandom.sty +0.02 2023-11-13 - fix for endless loop, + - added optional argument for special seed number 0.01 2018-12-15 first CTAN version (hv) diff --git a/macros/luatex/latex/luarandom/README b/macros/luatex/latex/luarandom/README index f51f725e01..a7abc86611 100644 --- a/macros/luatex/latex/luarandom/README +++ b/macros/luatex/latex/luarandom/README @@ -9,4 +9,4 @@ The macros for random numbers can only be used with LuaLaTeX! hvoss@tug.org -%% $Id: README 862 2018-12-15 16:25:55Z herbert $ +%% $Id: README 813 2023-11-13 19:33:29Z herbert $ diff --git a/macros/luatex/latex/luarandom/doc/luarandom-doc.pdf b/macros/luatex/latex/luarandom/doc/luarandom-doc.pdf index 9f137411ad..04287903aa 100644 Binary files a/macros/luatex/latex/luarandom/doc/luarandom-doc.pdf and b/macros/luatex/latex/luarandom/doc/luarandom-doc.pdf differ diff --git a/macros/luatex/latex/luarandom/doc/luarandom-doc.tex b/macros/luatex/latex/luarandom/doc/luarandom-doc.tex index 6c17c1647d..069d239d07 100644 --- a/macros/luatex/latex/luarandom/doc/luarandom-doc.tex +++ b/macros/luatex/latex/luarandom/doc/luarandom-doc.tex @@ -1,9 +1,8 @@ -%% $Id: luarandom-doc.tex 862 2018-12-15 16:25:55Z herbert $ +%% $Id: luarandom-doc.tex 813 2023-11-13 19:33:29Z herbert $ \documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false, headings=small, headinclude=false,footinclude=false,oneside,abstract=on]{pst-doc} \usepackage{xcolor,pstricks,multido} -\usepackage{auto-pst-pdf-lua} \usepackage{luarandom} \let\pstMathFV\fileversion @@ -21,7 +20,7 @@ x&\mapsto&{\operator@font#1}(x)\end{array}\right.} \begin{document} \title{\texttt{luarandom}} -\subtitle{Create a list of random numbers with or without multiple values; v. 0.01} +\subtitle{Create a list of random numbers with or without multiple values; v. 0.02} \author{Herbert Vo\ss} \docauthor{Herbert Vo\ss} \date{\today} @@ -39,8 +38,8 @@ However, this package will \emph{not} run with other \TeX-engines than Lua\LaTe \section{The Macros} \begin{BDef} -\Lcs{makeSimpleRandomNumberList}\Largb{Left}\Largb{Right}\Largb{N}\% multiple values possible\\ -\Lcs{makeRandomNumberList}\Largb{Left}\Largb{Right}\Largb{N} \% no multiple values!\\ +\Lcs{makeSimpleRandomNumberList}\OptArg{Seed}\Largb{Left}\Largb{Right}\Largb{N}\% multiple values possible\\ +\Lcs{makeRandomNumberList}\OptArg{Seed}\Largb{Left}\Largb{Right}\Largb{N} \% no multiple values!\\ \Lcs{getNumberFromList}\Largb{number} \end{BDef} @@ -61,10 +60,33 @@ The list of the random numbers is saved in the Lua table \texttt{RandomNumbers}. \end{LTXexample} +With the optional argument \verb|[seed number]|, the seed function is not called +with the current time, but with the optional value (integer). -The following example uses PSTricks related packages which cannot be run directly -with Lua\LaTeX. The package \LPack{auto-pst-pdf-lua} will convert the PSTricks stuff -in the baclground into PDF images which will be included in a second run. +\begin{LTXexample}[pos=t] +\small +\makeSimpleRandomNumberList[999]{1}{30}{30}% with multiple values and value seed +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } + +\makeRandomNumberList[999]{1}{30}{30}% without multiple values and value seed +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } + +\makeSimpleRandomNumberList[999]{1}{30}{30}% with multiple values and value seed +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } + +\makeRandomNumberList{1}{30}{30}% without multiple values and time seed +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } +\end{LTXexample} + + +\begin{LTXexample}[pos=t] +\makeRandomNumberList{2}{30}{5}% +\multido{\iA=1+1}{5}{\getNumberFromList{\iA}, } +\end{LTXexample} + + +The following example uses PSTricks related packages which can be run directly +with Lua\LaTeX. \begin{LTXexample}[pos=t] @@ -79,7 +101,6 @@ in the baclground into PDF images which will be included in a second run. \end{pspicture} \end{LTXexample} - \section{The code} \lstinputlisting{luarandom.sty} diff --git a/macros/luatex/latex/luarandom/latex/luarandom.sty b/macros/luatex/latex/luarandom/latex/luarandom.sty index a0be7f3c49..ea13d340b0 100644 --- a/macros/luatex/latex/luarandom/latex/luarandom.sty +++ b/macros/luatex/latex/luarandom/latex/luarandom.sty @@ -1,10 +1,10 @@ -% $Id: luarandom.sty 862 2018-12-15 16:25:55Z herbert $ +% $Id: luarandom.sty 813 2023-11-13 19:33:29Z herbert $ %% %% This is file `luarandom.sty'. %% %% IMPORTANT NOTICE: %% -%% luarandom Copyright (C) 2019- Herbert Voss +%% luarandom Copyright (C) 2018,2023- Herbert Voss %% %% This package may be distributed under the terms of the LaTeX Project %% Public License, as described in lppl.txt in the base LaTeX distribution. @@ -12,8 +12,9 @@ %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{luarandom}[2018/12/16 v 0.01 package for random numbers] -\RequirePackage{ifluatex} +\ProvidesPackage{luarandom}[2023/11/12 v 0.02 package for random numbers] +\RequirePackage{iftex} + \def\lua@nl{^^J\space\space\space\space} \newcommand\lua@PackageError[2]{\PackageError{luarandom}{\lua@nl #1^^J}{#2}} \ifluatex\else @@ -39,24 +40,32 @@ function allFound(R) return true end -function makeRandomNumberList(l,r,n) +function makeRandomNumberList(l,r,n,seed) RandomNumbers = {} - math.randomseed(os.time()) + if seed == 0 then + math.randomseed(os.time()) + else + math.randomseed(seed) + end local R = {} local i,j for i=1,n do R[i] = false end repeat local rand = math.random(l,r) - if not R[rand] then - R[rand] = true + if not R[rand+1-l] then + R[rand+1-l] = true RandomNumbers[#RandomNumbers+1] = rand end until allFound(R) end -function makeSimpleRandomNumberList(l,r,n) +function makeSimpleRandomNumberList(l,r,n,seed) RandomNumbers = {} - math.randomseed(os.time()/3) + if seed == 0 then + math.randomseed(os.time()/3) + else + math.randomseed(seed) + end local i for i=1,n do RandomNumbers[#RandomNumbers+1] = math.random(l,r) end end @@ -66,10 +75,10 @@ function getRand(i) end \end{luacode*} -\def\makeRandomNumberList#1#2#3{% - \directlua{makeRandomNumberList(#1,#2,#3)}} -\def\makeSimpleRandomNumberList#1#2#3{% - \directlua{makeSimpleRandomNumberList(#1,#2,#3)}} +\newcommand\makeRandomNumberList[4][0]{% + \directlua{makeRandomNumberList(#2,#3,#4,#1)}} +\newcommand\makeSimpleRandomNumberList[4][0]{% + \directlua{makeSimpleRandomNumberList(#2,#3,#4,#1)}} \def\getNumberFromList#1{\directlua{getRand(#1)}} -- cgit v1.2.3