diff options
author | Karl Berry <karl@freefriends.org> | 2018-12-15 22:41:11 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-12-15 22:41:11 +0000 |
commit | b0897576fe379e6d9a0edd6aaa598b8b0d96cfbd (patch) | |
tree | c5abfb20f4ad066073832322369d08177a67b904 /Master/texmf-dist | |
parent | f1106de84d0ef7b3aa67dc256c8bcc03aa36b116 (diff) |
luarandom (15dec18)
git-svn-id: svn://tug.org/texlive/trunk@49419 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/luarandom/Changes | 4 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/luarandom/README | 12 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.pdf | bin | 0 -> 49787 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.tex | 90 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/luarandom/luarandom.sty | 76 |
5 files changed, 182 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/lualatex/luarandom/Changes b/Master/texmf-dist/doc/lualatex/luarandom/Changes new file mode 100644 index 00000000000..29cf20e0232 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/luarandom/Changes @@ -0,0 +1,4 @@ +..... luarandom.sty +0.01 2018-12-15 first CTAN version (hv) + + diff --git a/Master/texmf-dist/doc/lualatex/luarandom/README b/Master/texmf-dist/doc/lualatex/luarandom/README new file mode 100644 index 00000000000..f51f725e010 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/luarandom/README @@ -0,0 +1,12 @@ +# luarandom.sty # + +This package provides some macros for creating random number +lists between a nd b (Integers). This list can have multiple +numbers or not. + +The macros for random numbers can only be used with LuaLaTeX! + +hvoss@tug.org + + +%% $Id: README 862 2018-12-15 16:25:55Z herbert $ diff --git a/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.pdf b/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.pdf Binary files differnew file mode 100644 index 00000000000..9f137411ad0 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.pdf diff --git a/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.tex b/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.tex new file mode 100644 index 00000000000..6c17c1647d3 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/luarandom/luarandom-doc.tex @@ -0,0 +1,90 @@ +%% $Id: luarandom-doc.tex 862 2018-12-15 16:25:55Z 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 +\lstset{pos=t,wide=true,language=[LaTeX]{TeX},basicstyle=\footnotesize\ttfamily} +% +\makeatletter +\def\DefOfOperator{\@ifstar{\DefOfOperator@}{\DefOfOperator@@}} +\def\DefOfOperator@#1#2#3#4{{\operator@font#1}:\left\{\begin{array}{ccc} #2&\to\\ +x&\mapsto\end{array}\right.} +\def\DefOfOperator@@#1#2#3{{\operator@font#1}:\left\{\begin{array}{ccc} #2&\to\\ +x&\mapsto&{\operator@font#1}(x)\end{array}\right.} +\makeatother + + +\begin{document} + +\title{\texttt{luarandom}} +\subtitle{Create a list of random numbers with or without multiple values; v. 0.01} +\author{Herbert Vo\ss} +\docauthor{Herbert Vo\ss} +\date{\today} +\maketitle + +\tableofcontents + + +\section{Random numbers} +Package \LPack{luarandom} supports the creation of random number lists where a number will +appear only once or multiple times. With Lua\TeX\ all random numbers are build with the help of Lua which +has the advantage that there will be no problem with \TeX's limited parameter stack size. +However, this package will \emph{not} run with other \TeX-engines than Lua\LaTeX. + + +\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{getNumberFromList}\Largb{number} +\end{BDef} + + +The list of the random numbers is saved in the Lua table \texttt{RandomNumbers}. + + +\section{Examples} + + +\begin{LTXexample}[pos=t] +\small +\makeSimpleRandomNumberList{1}{30}{30}% with multiple values (hopefully ;-) +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } + +\makeRandomNumberList{1}{30}{30}% without multiple values +\multido{\iA=1+1}{30}{\getNumberFromList{\iA}, } +\end{LTXexample} + + + +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] +\newcounter{RandNo}\setcounter{RandNo}{1} +\def\n{10} \def\N{\the\numexpr\n*\n} +\makeRandomNumberList{1}{\N}{\N} +\begin{pspicture}(\n,\n) + \psgrid[subgriddiv=0,gridlabels=0pt] + \multido{\rRow=0.5+1.0}{\n}{\multido{\rCol=0.5+1.0}{\n}{% + \rput(\rCol,\rRow){\textcolor{randomhsb}{\getNumberFromList{\theRandNo}}}% + \stepcounter{RandNo}}} +\end{pspicture} +\end{LTXexample} + + +\section{The code} + +\lstinputlisting{luarandom.sty} + +\printindex + + +\end{document} diff --git a/Master/texmf-dist/tex/lualatex/luarandom/luarandom.sty b/Master/texmf-dist/tex/lualatex/luarandom/luarandom.sty new file mode 100644 index 00000000000..a0be7f3c498 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/luarandom/luarandom.sty @@ -0,0 +1,76 @@ +% $Id: luarandom.sty 862 2018-12-15 16:25:55Z herbert $ +%% +%% This is file `luarandom.sty'. +%% +%% IMPORTANT NOTICE: +%% +%% luarandom Copyright (C) 2019- Herbert Voss <hvoss@tug.org> +%% +%% This package may be distributed under the terms of the LaTeX Project +%% Public License, as described in lppl.txt in the base LaTeX distribution. +%% Either version 1.3 or, at your option, any later version. +%% + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{luarandom}[2018/12/16 v 0.01 package for random numbers] +\RequirePackage{ifluatex} +\def\lua@nl{^^J\space\space\space\space} +\newcommand\lua@PackageError[2]{\PackageError{luarandom}{\lua@nl #1^^J}{#2}} +\ifluatex\else + \lua@PackageError{% + "You are not using LuaTeX\app@nl + the lua definitions will not be available!} + {If you run the source from a GUI then set + the compiler "lualatex" in the + preferences.}% +\fi + +\RequirePackage{luacode} +\begin{luacode*} +RandomNumbers = {} + +function allFound(R) + local r1 = R[1] + local i + for i=2,#R do + r1 = r1 and R[i] + if not r1 then return false end + end + return true +end + +function makeRandomNumberList(l,r,n) + RandomNumbers = {} + math.randomseed(os.time()) + 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 + RandomNumbers[#RandomNumbers+1] = rand + end + until allFound(R) +end + +function makeSimpleRandomNumberList(l,r,n) + RandomNumbers = {} + math.randomseed(os.time()/3) + local i + for i=1,n do RandomNumbers[#RandomNumbers+1] = math.random(l,r) end +end + +function getRand(i) + tex.print(RandomNumbers[i]) +end +\end{luacode*} + +\def\makeRandomNumberList#1#2#3{% + \directlua{makeRandomNumberList(#1,#2,#3)}} +\def\makeSimpleRandomNumberList#1#2#3{% + \directlua{makeSimpleRandomNumberList(#1,#2,#3)}} +\def\getNumberFromList#1{\directlua{getRand(#1)}} + + +\endinput |