summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/supp-ran.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-04-18 22:52:45 +0000
committerKarl Berry <karl@freefriends.org>2015-04-18 22:52:45 +0000
commit16aa5a7c87f18a2483d0d61795899f886781b51c (patch)
tree1d72f00b2a4185425393598402fe055c61d1de58 /Master/texmf-dist/tex/context/base/supp-ran.lua
parente68dc4d5506d46bf72823234f902bc76d1f70352 (diff)
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
Diffstat (limited to 'Master/texmf-dist/tex/context/base/supp-ran.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/supp-ran.lua42
1 files changed, 25 insertions, 17 deletions
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 } }
+