I have these four variables:
1 | local RarityBasic = 0.4 -- The probability. |
2 | local RarityRare = 0.3 |
3 | local RarityLegendary = 0.2 |
4 | local RarityExotic = 0.1 |
Where the number is the probability. I want a way of randomly choosing one of them taking into account the probability that each thing has.
The output would be something like:
1 | print ( "Rarity: " ..Rarity) |
2 | >> Rarity: Basic |
How would I do this?
Do something like this :
01 | math.randomseed(tick()) |
02 | local number = math.random( 1 , 10 ) |
03 | if number = = 1 then |
04 | print ( "Rarity : Exotic" ) |
05 | elseif number > = 2 and number < = 3 then |
06 | print ( "Rarity : Legendary" ) |
07 | elseif number > = 4 and number < = 6 then |
08 | print ( "Rarity : Rare" ) |
09 | elseif number > = 7 and number < = 10 then |
10 | print ( "Rarity : Basic" ) |
11 | end |
It basically assigns different chances to each rarity so the exotic has a 10% chance, legendary has 20% chance, etc.