So, I have a table called t. I want to randomly find a number from the table, and then remove that number from the table so the next number can’t be the same number as the first. In total, I have four numbers. But when I run the code, every time I get a 1, 5, 2, 5, which shouldn’t possible because I supposedly removed 5 already from the table . How come it I get this result?
--create the table t = {1, 2, 3, 4, 5, 6, 7, 8, 9} --randomly find 1st number from t then remove number1 = math.random(#t) table.remove(t, number1) print ("number 1 is " .. number1) --randomly find 2nd number from t then remove number2 = math.random(#t) table.remove(t, number2) print ("number 2 is " .. number2) --randomly find 3rd number from t then remove number3 = math.random(#t) table.remove(t, number3) print ("number 3 is " .. number3) --randomly find 4th number from t then remove number4 = math.random(#t) table.remove(t, number4) print ("number 4 is " .. number4) --Result: 1 5 2 5 which shouldn't be possible!