Rodmastercraft

ProbHability

Apr 4th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. function random(min, max)
  2.        r = math.random(min, max)
  3.        return r
  4. end
  5.  
  6. function calc(prob, maxi)
  7.        if maxi then
  8.               if prob > maxi then
  9.                      error("Prob. higher than "..maxi..". Enter a number at second parameter or decrease the prob. rate.")
  10.               else
  11.                      prob = tonumber(prob)
  12.                      pr = random(1, maxi)
  13.                      if pr < prob then
  14.                             return true
  15.                      else
  16.                             return false
  17.                      end
  18.               end
  19.        else
  20.               if prob > 100 then
  21.                      error("Prob. higher than 100. Enter a number at second parameter or decrease the prob. rate.")
  22.               else
  23.                      prob = tonumber(prob)
  24.                      pr = random(1, 100)
  25.                      if pr < prob then
  26.                             return true
  27.                      else
  28.                             return false
  29.                      end
  30.               end
  31.        end
  32. end
  33.  
  34. local function error(param)
  35.        printError(param)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment