system
February 20, 2019, 1:25am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
maer
Hello,
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 )
#1
#1
#4
or
for i in range(3):
print(rand_range(0, 8))
#5.668026
#7.775277
#2.76658
I tried to restart application 10 times with the same result.
Is it possible to make totally random numbers in some range?
Thank you,
system
February 20, 2019, 1:54am
2
Reply From:
RenenerG
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( ):
randomize()
This should generate a new seed for the random number generator. Therefore every new run should have other numbers.
see randomize for more information
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!
Dani Ximple Apps | 2020-12-19 18:42