Is there a way to randomize between two numbers, like 1 and 2, but 1 has a higher chance of always being chosen?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LanzA

Hi, im still new on Godot

So i have a spawn point which should randomly spawn between two kinds of enemies, 1 is weaker and 2 is stronger. So basically i want to spawn more weaker enemies than the stronger one. I have already found a way to randomize between the two with help from yt and here, but still cant seem to find what i was looking for. So thank you in advance for anyone for the help.

:bust_in_silhouette: Reply From: 1234ab

you could use e.g. randf( ) which returns between 0 and 1, RandomNumberGenerator — Godot Engine (stable) documentation in English
so you can do something like this:

if randf() > 0.8:

and this will spawn weak 80% of the time and strong 20% of the time
there may be a better method but this is one way to do it