Material Box

Material Box

WEB Design & Material Images

Godot - Generate a random integer

Godot

This is how to generate a random integer using GDScript in Godot 4.


You can generate a random integer using randi_range().
The first argument is the minimum value of the range, and the second argument is the maximum value of the range.

randi_range() has the following characteristics:
- It gets a random integer between the first and second arguments

var randomRange = randi_range(0, 100)

To get a random decimal number, use randf_range().

var randomRange = randf_range(0, 2)
# 0.55864010048881

Godot

TitleGodot - Generate a random integer

CategoryGodot

Created

Update

AuthorYousuke.U