From 16aa5a7c87f18a2483d0d61795899f886781b51c Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 18 Apr 2015 22:52:45 +0000 Subject: context, from www.pragma-ade.com/context/beta/cont-tmf.zip (18apr15) git-svn-id: svn://tug.org/texlive/trunk@36923 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/context/base/supp-ran.lua | 42 +++++++++++++++---------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'Master/texmf-dist/tex/context/base/supp-ran.lua') diff --git a/Master/texmf-dist/tex/context/base/supp-ran.lua b/Master/texmf-dist/tex/context/base/supp-ran.lua index 7997db8f648..1d34393fa64 100644 --- a/Master/texmf-dist/tex/context/base/supp-ran.lua +++ b/Master/texmf-dist/tex/context/base/supp-ran.lua @@ -10,12 +10,16 @@ if not modules then modules = { } end modules ['supp-ran'] = { local report_system = logs.reporter("system","randomizer") -local math = math -local context, commands = context, commands +local math = math +local context = context +local implement = interfaces.implement -local random, randomseed, round, seed, last = math.random, math.randomseed, math.round, false, 1 - -local maxcount = 2^30-1 -- 1073741823 +local random = math.random +local randomseed = math.randomseed +local round = math.round +local seed = false +local last = 1 +local maxcount = 2^30-1 -- 1073741823 local function setrandomseedi(n,comment) if not n then @@ -34,28 +38,23 @@ end math.setrandomseedi = setrandomseedi -function commands.getrandomcounta(min,max) +local function getrandomnumber(min,max) last = random(min,max) - context(last) -end - -function commands.getrandomcountb(min,max) - last = random(min,max)/65536 - context(last) + return last end -function commands.setrandomseed(n) +local function setrandomseed(n) last = n setrandomseedi(n) end -function commands.getrandomseed(n) - context(last) +local function getrandomseed() + return last end -- maybe stack -function commands.freezerandomseed(n) +local function freezerandomseed(n) if seed == false or seed == nil then seed = last setrandomseedi(seed,"freeze",seed) @@ -65,9 +64,18 @@ function commands.freezerandomseed(n) end end -function commands.defrostrandomseed() +local function defrostrandomseed() if seed ~= false then setrandomseedi(seed,"defrost",seed) -- was last (bug) seed = false end end + +implement { name = "getrandomnumber", actions = { getrandomnumber, context }, arguments = { "integer", "integer" } } +implement { name = "getrandomdimen", actions = { getrandomnumber, context }, arguments = { "dimen", "dimen" } } +implement { name = "getrandomfloat", actions = { getrandomnumber, context }, arguments = { "number", "number" } } +implement { name = "setrandomseed", actions = { setrandomseed }, arguments = { "integer" } } +implement { name = "getrandomseed", actions = { getrandomseed, context } } +implement { name = "freezerandomseed", actions = { freezerandomseed } } +implement { name = "defrostrandomseed", actions = { defrostrandomseed } } + -- cgit v1.2.3