Skip to content

Instantly share code, notes, and snippets.

@jyrkive
Created June 28, 2018 17:19
Show Gist options
  • Save jyrkive/08807b2e4c8b8660c2935e9e7161b647 to your computer and use it in GitHub Desktop.
Save jyrkive/08807b2e4c8b8660c2935e9e7161b647 to your computer and use it in GitHub Desktop.
function weighted_random(odds)
local target = wesnoth.random()
local sum = 0.0
local i = 1
sum += odds[1]
while sum <= target and i <= #odds do
sum += odds[i]
i += 1
end
return i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment