title: Effectively remove nil values from lua table
body: <p>I am new to lua and fairly new to programming. I am trying to achieve the following.</p>
  
  <p>I have a table of numbers from which I pick a random number.</p>
  
  <pre><code>myTable = {}
  
  for i = 1 to 100 do 
     table.insert(myTable, i)
  end
  
  local numberChosen = myTable[math.random(#myTable)]
  </code></pre>
  
  <p>So far, so good. The next time a number is picked, I want that number to be removed from the table. I know lua doesn't remove values, they stay there as nil. So</p>
  
  <pre><code>table.remove(myTable, numberChosen)
  </code></pre>
  
  <p>Doesn't work as when I try to run the random function again, if the value is nil, I get
  "bad argument #1 to 'random' (interval is empty)"</p>
  
  <p>I have tried creating a function like this:</p>
  
  <pre><code>function cleanTable(t)
      local  cleanTable = {}
      for k, v in ipairs(t)do
          if v ~= nil then
              table.insert(cleanTable, v)
          end
      end
      return cleanTable
  end
  
  myTable = cleanTable(myTable)
  </code></pre>
  
  <p>But that does't work either as the random function returns the same error. Can anyone help?</p>
  
  <p>edit ----------------------------------------------------------------------</p>
  
  <p>My table contains keys and values like so:</p>
  
  <pre><code>local columns = {1,2,3,4,5,6,7,8,9,10,11,12}
  local rows = {1,2,3,4,5,6,7,8,9,10,11,12}
  local coupledNumbers = {}
  
  
  for i = 1, #columns do
      for a = 1, #rows do
          local coupledNumber = i * a
          table.insert(coupledNumbers, i*a, coupledNumber)
      end
  end
  </code></pre>
  
  <p>How do I remove the key and the value? thanks</p>