How to select multiple random elements from a LUA table?

I'm trying to figure out how to randomly select multiple entries in a table.

This is what I have currently


local letters = {"w", "x", "y", "z"}


function randomletterselect()
    local randomletters = {}
    
    for i,v in pairs(letters) do
        table.insert(randomletters,i)
    end
    local letter = letters[randomletters[math.random(#randomletters)]]
    -- set multiple selected letters to the new table?

end
randomletterselect()

this code here works for selecting ONE random element(letter) from the table. essentially, when I run this, I want it to be multiple random letters selected. for example, one time it may select x,y another time it may be x,y,z.

The closest thing I found was honestly just what I had figured out, in this post Randomly select a key from a table in Lua



from Recent Questions - Stack Overflow https://ift.tt/3e6xDgn
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Hibernate JPA @OnDelete Example