How to get a random item from an array?

For the past few hours I’ve been trying to find how get a random item from an array, as the title says. I just haven’t found a single thing that actually works.

And I’ve tried doing table[math.random(1,#table)] and that doesn’t work.

List -

local difficulties = {
	easy = {number = 3, text = "Not too bad!", tim = 20},
	medium = {number = 6, text = "Kinda hard...", tim = 45},
	hard = {number = 12, text = "Really spicy!!!!!!!", tim = 75}
}

That is actually a dictionary and not an array.

You can look at this post for a function that should do the job:

1 Like

Thank you!! The one you linked me didn’t help, but another comment under the post did.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.