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?

in Engine by (515 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()

by (362 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.