How do I make a number be random from 1 to 2 but 2 must be 25% chance be the number?

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

I want to make an “Action RPG” game and I want the damage on the player to be 1 but there to be a 25% chance for it being 2

:bust_in_silhouette: Reply From: Zylann

So you want damage to be 1 in 75% cases, and 2 in 25% cases?
This would work:

if randf() < 0.75:
	damage = 1
	damage = 2

what does randf() do? Could you link the documentation to it?

Millard | 2020-05-28 20:28

It generates a decimal number between 0 and 1
@GDScript — Godot Engine (stable) documentation in English

Zylann | 2020-05-28 20:41