1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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
|