Skip to content

Commit

Permalink
allow to to use a custom rng in helper.rand
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Apr 7, 2017
1 parent 99de242 commit 8c4e09e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions data/lua/helper.lua
Expand Up @@ -402,7 +402,8 @@ function helper.shallow_parsed(cfg)
end
end

function helper.rand (possible_values)
function helper.rand (possible_values, random_func)
random_func = random_func or wesnoth.random
assert(type(possible_values) == "table" or type(possible_values) == "string", string.format("helper.rand expects a string or table as parameter, got %s instead", type(possible_values)))

local items = {}
Expand Down Expand Up @@ -460,7 +461,7 @@ function helper.rand (possible_values)
end
end

local idx = wesnoth.random(1, num_choices)
local idx = random_func(1, num_choices)

for i, item in ipairs(items) do
if type(item) == "table" then -- that's a range
Expand Down

0 comments on commit 8c4e09e

Please sign in to comment.