0 votes

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?

asked Jan 21, 2017 in Engine by DodoIta (447 points)

1 Answer

+4 votes
Best answer


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()

answered Jan 21, 2017 by Nutr1z (342 points)
selected Mar 15, 2017 by DodoIta

It works, thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.