summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-12-15 22:41:11 +0000
committerKarl Berry <karl@freefriends.org>2018-12-15 22:41:11 +0000
commitb0897576fe379e6d9a0edd6aaa598b8b0d96cfbd (patch)
treec5abfb20f4ad066073832322369d08177a67b904 /Master/texmf-dist/tex/lualatex
parentf1106de84d0ef7b3aa67dc256c8bcc03aa36b116 (diff)
luarandom (15dec18)
git-svn-id: svn://tug.org/texlive/trunk@49419 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/luarandom/luarandom.sty76
1 files changed, 76 insertions, 0 deletions
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