vendredi 10 septembre 2021

Lua - How can I select numbers from a list randomly, with different probabilities of getting selected for each number?

I have 4 numbers [1, 2, 3, 4]

I want to pick numbers out of this list randomly while giving the most probability to 1 (approx 0.43), next 3 (approx 0.38), and least and equal probabilities to 2 and 4 (approx 0.09 each).

How can I do this in Lua?

This is what I have tried so far.

codeList = {1, 2, 3, 4}
number = codeList[math.random(#codeList)]



Aucun commentaire:

Enregistrer un commentaire