summaryrefslogtreecommitdiff
path: root/src/rng.moon
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-21 16:03:25 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-21 16:03:25 -0600
commit89a8f94ac0206412c1a2d7b8766d97dbdbd36253 (patch)
treec9ddc23d31d3c5058d3465dabb68aae7b8209138 /src/rng.moon
parent0370d64b3bd7914be55358817e52bbc8a529a7d3 (diff)
downloadggj25-89a8f94ac0206412c1a2d7b8766d97dbdbd36253.tar.gz
ggj25-89a8f94ac0206412c1a2d7b8766d97dbdbd36253.tar.bz2
ggj25-89a8f94ac0206412c1a2d7b8766d97dbdbd36253.zip
work
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