summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-ran.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-10-19 01:20:13 +0300
committerMarius <mariausol@gmail.com>2012-10-19 01:20:13 +0300
commit69d2352af4b60929b37fc49f3bdb263977016244 (patch)
treedb5eb11398e345dfa23b4c4500fb93575d2afb7c /tex/context/base/supp-ran.lua
parentc18f7cbe51449a611ea1819fedd9a4ff18529b7d (diff)
downloadcontext-69d2352af4b60929b37fc49f3bdb263977016244.tar.gz
stable 2012.05.30 11:26
Diffstat (limited to 'tex/context/base/supp-ran.lua')
-rw-r--r--tex/context/base/supp-ran.lua28
1 files changed, 14 insertions, 14 deletions
diff --git a/tex/context/base/supp-ran.lua b/tex/context/base/supp-ran.lua
index 7997db8f6..75202f696 100644
--- a/tex/context/base/supp-ran.lua
+++ b/tex/context/base/supp-ran.lua
@@ -6,34 +6,32 @@ if not modules then modules = { } end modules ['supp-ran'] = {
license = "see context related readme files"
}
--- We cannot ask for the current seed, so we need some messy hack here.
+-- We cannot ask for the current seed, so we need some messy hack
+-- here.
local report_system = logs.reporter("system","randomizer")
-local math = math
-local context, commands = context, commands
+commands = commands or { }
+local commands = commands
+local math = math
local random, randomseed, round, seed, last = math.random, math.randomseed, math.round, false, 1
-local maxcount = 2^30-1 -- 1073741823
-
-local function setrandomseedi(n,comment)
+function math.setrandomseedi(n,comment)
if not n then
- -- n = 0.5 -- hack
+--~ n = 0.5 -- hack
end
if n <= 1 then
- n = n * maxcount
+ n = n*1073741823 -- maxcount
end
n = round(n)
if false then
report_system("setting seed to %s (%s)",n,comment or "normal")
end
randomseed(n)
- last = random(0,maxcount) -- we need an initial value
+ last = random(0,1073741823) -- we need an initial value
end
-math.setrandomseedi = setrandomseedi
-
function commands.getrandomcounta(min,max)
last = random(min,max)
context(last)
@@ -46,7 +44,7 @@ end
function commands.setrandomseed(n)
last = n
- setrandomseedi(n)
+ math.setrandomseedi(n)
end
function commands.getrandomseed(n)
@@ -56,9 +54,10 @@ end
-- maybe stack
function commands.freezerandomseed(n)
+ -- print("<<<<",seed,last)
if seed == false or seed == nil then
seed = last
- setrandomseedi(seed,"freeze",seed)
+ math.setrandomseedi(seed,"freeze",seed)
end
if n then
randomseed(n)
@@ -66,8 +65,9 @@ function commands.freezerandomseed(n)
end
function commands.defrostrandomseed()
+ -- print(">>>>",seed,last)
if seed ~= false then
- setrandomseedi(seed,"defrost",seed) -- was last (bug)
+ math.setrandomseedi(seed,"defrost",seed) -- was last (bug)
seed = false
end
end