I need help randomising a question

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pointlessperson1

So im trying to make my variable a random number and ive used

func _randomise_my_variable(): a = randi()%10 +1

but this puts out numbers in exactly the same order every time

Is this just me or is something wrong

:bust_in_silhouette: Reply From: Zedespook

In the _ready() func put randomize() to randomize the seed, so that it generates a different value every time. Hope this helps!

:bust_in_silhouette: Reply From: Slavs Make Games

For random number creation, you need two commands randi and randomize.
In the example, you will have code make a random number from 1 to 12.

func _ready():
       print( randi() % 12 + 1 )

Randi will always generate the same number, but with “randomize” generate become random.

randi() 	  # returns random integer between 0 and 2^32 – 1
randi() % 20  # returns random integer between 0 and 19

Enjoy in randomizing!