#Determine fish type based on percentages.

4 messages · Page 1 of 1 (latest)

worldly shadow
#

A bit confused on your question. Are you asking how to make a function that will return a random fish based on the percentage chance?

real cloak
#

i can help you, dm me if you want me to. im not pro but i think this is easy enough

inland sierra
#

You're looking for weighted probability, there are a few ways you could go at this. The simplest one is on https://docs.godotengine.org/en/stable/tutorials/math/random_number_generation.html#weighted-random-probability, but if you google for it (godot-specific or not) there are a lot of examples

errant geyser
#

try this:

var dict : Dictionary = {1:12, 2:10, 3:8, 4:2, 5:6, 6:13, 7:18, 8:3, 9:100 - 72}
func get_random_index():
    var randomValue = randf()
    for i in dict.size():
        if randomValue < dict[i]:
            return i
    return 9