+2 votes


I am trying to generate random number but the following code returns always the same numbers after every restart:

for i in range(3):
    print( randi()%8 )


for i in range(3):
     print(rand_range(0, 8))

I tried to restart application 10 times with the same result.

Is it possible to make totally random numbers in some range?

Thank you,

in Engine by (24 points)

1 Answer

+3 votes
Best answer

Hello maer,

sounds like that you could try to call randomize() in the _ready() function, in the script, where you try to generate random numbers.

func _ready( ):

This should generate a new seed for the random number generator. Therefore every new run should have other numbers.

see randomize for more information

by (258 points)
selected by

Thanks, work like a charm.

Thanks, I've got the same problem and now my game will change every match. I was thinking "Why the bubble always Spam in the same place??" and now I understand all. Thanks, thanks, thanks!

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 Frequently asked questions and 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 [email protected] with your username.