summaryrefslogtreecommitdiff
path: root/src/rng.moon
diff options
context:
space:
mode:
Diffstat (limited to 'src/rng.moon')
-rw-r--r--src/rng.moon10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/rng.moon b/src/rng.moon
index d732386..2c995f2 100644
--- a/src/rng.moon
+++ b/src/rng.moon
@@ -3,12 +3,20 @@ rng = {}
totally_random_seed = tonumber(os.date("%Y%H%M%S"))
math.randomseed(totally_random_seed)
+-- same syntax as math.random, if m and n are passed, they are lower and upper bounds
+-- if only m is passed, it is the upper bound
+-- if neither is passed, between 0 and 1
rng.generator = (seed, m, n) ->
seed = seed or tonumber(os.date("%Y%S"))
co = coroutine.wrap(() ->
while true
math.randomseed(seed)
- seed = math.random(m,n)
+ if m and n
+ seed = math.random(m,n)
+ elseif m
+ seed = math.random(m)
+ else
+ seed = math.random()
coroutine.yield(seed)
)
co, seed