Skip to content

Commit

Permalink
KaraTemplater: create util.rand submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
The0x539 committed Jun 27, 2021
1 parent 881390a commit 987d3c9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/0x.KaraTemplater.moon
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ util = (tenv) ->

(x - x0) / (x1 - x0)

rand:
-- Either -1 or 1, randomly.
sign: -> math.random(0, 1) * 2 - 1

-- A random entry from a list.
item: (list) -> list[math.random 1, #list]

-- A boolean with a truth probability of p.
bool: (p=0.5) -> math.random! < p

-- The shared global scope for all template code.
class template_env
:_G, :math, :table, :string, :unicode, :tostring, :tonumber, :aegisub, :error, :karaskel, :require
Expand Down

0 comments on commit 987d3c9

Please sign in to comment.