randi() function not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DodoIta
:warning: Old Version Published before Godot 3 was released.

Hi!
I’m having problems generating a random integer number from 0 to 12.
I’m new to gdscript and game engines in general, but even though the use of the randi() function should be easy, I can’t make it work, since writing the following code doesn’t work:

	var random = randi() % 13

I printed random and it’s always equal to 2.

Can any of you guys tell me what the problem is?

:bust_in_silhouette: Reply From: Nutr1z

Hi,

same sample code work for me :

random: 2
random: 9
random: 5
random: 7
random: 8
random: 8
random: 2
random: 12
random: 11

But yes, if I rerun my game, it return the same suite of numbers, if you want another random suite, you must call randomize() before randi()

It works, thank you!

DodoIta | 2017-01-21 11:00