Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- extension of math lib
- local math = require "math"
- math.clamp = function(value, lower, upper)
- if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way
- return math.max(lower, math.min(upper, value))
- end
- math.sign = function(value) -- Copyright 2013 Arman Darini
- if value > 0 then return 1; elseif value < 0 then return -1; else return 0; end
- end
- math.round = function(value)
- return math.floor(value + 0.5)
- end
- math.dice = function(dice, side)
- local value = 0
- for i = 1, dice do
- value = value + math.random(1, side)
- end
- return value
- end
- -- Probability distribution function
- --
- -- if 'probabilityPower' is above 1, lower values will be more common than higher values
- -- if it's between 0 to 1, higher values will be more common than lower values.
- -- If it's 1, the results will be in a general randomness.
- math.randomP = function(min, max, probabilityPower)
- return math.floor(min + (max + 1 - min) * (math.pow(math.random(), probabilityPower)))
- end
- -- @param number 0.0 - 1.0
- math.chance = function(chance)
- local value = math.random(0, 10000)
- if value/10000 <= chance then
- return true
- else
- return false
- end
- end
- return math
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement