How to randomize a table without using math.random

randomizing a table by doing:

table[math.random(1,#table)]

is trash, its usually not that random, if i had a table that had the letters X Y and Z, and i randomized it using table[math.random(1,#table)] it would print something like this

X, X, Y, Z, Y, X, X, X, Y, Y.

… which really isnt that random

im looking for a different way to randomize a table instead of using table[math.random(1,#table)]

You have a misunderstanding of what random is. If you have X Y and Z, there is a 33% chance that X will be picked. That chance doesn’t go down just because the last five choices were all X. It’s still a 33% chance. If you don’t want repetitions, that’s a different matter and it can be fixed. Or you can assign a weight to each entry in the table and make the weight halve every time that element is picked and increase every time it isn’t picked. There’s a lot of options here but what you’ve got is random enough that a human can’t definitively say whether it is or is not random.

So that said, what exactly do you want the behavior to be?

well, do you know how to not make it pick something twice?

The script is a death message script so it runs every time the character dies and resets when it respawns

You can shuffle the table and then iterate through it in order. I think that’s what you’re looking for.

2 Likes

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