Advertisement
alestane

Selection by share blance

Feb 29th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. function createSpawnSequence(inputBalance)
  2.     local outputString = ""
  3.     local totalSpawns = 0
  4.     for kind, count in pairs(inputBalance) do
  5.         totalSpawns = totalSpawns + count
  6.     end
  7.     for i = totalSpawns, 1, -1 do
  8.         i = math.random(i)
  9.         for kind, count in pairs(inputBalance) do
  10.             if i <= count then
  11.                 outputString = outputString .. "," .. kind
  12.                 inputBalance[kind] = count - 1
  13.                 break
  14.             else
  15.                 i = i - count
  16.             end
  17.         end
  18.     end
  19.     return string.sub(outputString, 2)
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement