I want each letter to only be used once when it prints on the last line, but it does some letters more than once, why?
local Pool={"a","b","c"} Pool[1] = Pool[math.random(1,#Pool)] local OM1 = Pool[1] table.remove(Pool, 1) Pool[1] = Pool[math.random(1,#Pool)] local OM2 = Pool[1] table.remove(Pool, 1) Pool[1] = Pool[math.random(1,#Pool)] local OM3 = Pool[1] table.remove(Pool, 1) print(OM1,OM2,OM3)
Each time, you're replacing the first element with a random one. This eliminates the first one at each step from being truly chosen later. You then eliminate that copy instead of the original.
That will look like this:
{a, b, c} {c, b, c} -- Pool[1] = Pool[3] {b, c} -- table.remove(Pool, 1) {c, c} -- Pool[1] = Pool[2] {c} -- table.remove(Pool, 1)
Here is how you remove a random thing from a list:
local O1 = table.remove(Pool, math.random(#Pool))
Note that the 1,
is optional in math.random
.